.bash_profile alias does not work in shell script
I have the following alias in my ~/.bash_profile
alias rdseed=/usr/local/rdseedv5.3.1/rdseed.mac.x86_64 When I call for rdseed in the terminal it works fine. However, when I call for it within a shell script I get the following error; "rdseed: command not found" When I add the exact line I have in my .bash_profile to the shell script and call it within the same script, it works fine. All other aliases I have in my .bash_profile works within a shell script without any problem. I am baffled. Any suggestions? Thanks! I am on MAC OS X (mountain lion) |
How are you running the script? Are you logging in then running it or is it running in background tool like cron?
In the former case your script should inherit your login environment (e.g. everything set in .bash_profile, /etc/profile or others) Prior to running the script if you run "alias" does it in fact show the defined alias? In the latter case you get a minimal environment (that is to say it does NOT run invoke .bash_profile and other things) so you don't get those. This includes aliases AND variables such as PATH. Since you are specifying the full path to the command in your alias that probably isn't the issue but the fact that defining it works may be. Also you might want to insure your first line of script is invoking the shell you expect. |
scripts don't expand aliases and don't bring in the current environment. so in script, after shabang, add this 'shopt -s expand_aliases'
Code:
#!/bin/bash |
All times are GMT -5. The time now is 01:06 PM. |