can't use alias
Closed this issue · 3 comments
Hi,
does bass support converting bash alias?
~> bass alias gcb="git pull" bash: line 0: alias: pull: not found exit code: 1 Bass encountered an error!
If I bass the following file...
~> cat kk.sh set -x alias gcb="git pull" alias gcb
...I get:
~> bass ./kk.sh
++ alias 'gcb=git pull'
++ alias
++ gcb
./kk.sh: line 4: gcb: command not found
exit code: 127
Bass encountered an error!
I saw #21, but the problem is that
alias "xx='echo lol'"
is not valid in bash
$ type xx
xx is aliased to `'echo lol''
$ xx
-bash: echo lol: command not found
It should be :
alias xx='echo lol'
⌂66% [dpinyol:~] $ type xx
xx is aliased to `echo lol'
⌂67% [dpinyol:~] $ xx
lol
thanks
Glad you find #21 :) I was about the comment that. Let me know if you run into any other issues.
Sorry for the late response. Your trouble was due to bash not expanding aliases in script mode. You just need to add shopt -s expand_aliases
to the beginning of your bash script.
For example:
$ cat kk.sh
shopt -s expand_aliases
set -x
alias gcb="python -V"
alias
gcb
Now this is a valid bash script. If you wish to execute the script, you don't need bass. You just need to bash it:
$ bash kk.sh
+ alias 'gcb=python -V'
+ alias
alias gcb='python -V'
+ python -V
Python 2.7.10
If what you want is to "inherit" the aliases and other environment variables in the script, then you have to source it, just like if your shell is bash:
$ bass source kk.sh
...
$ gcb
Python 2.7.10