Calling alias command in script
I created an alias that is called "temp" and I am trying to call that in a script I wrote. I don't think it is in the path though. Does anyone know how I would go about either putting it in the path or calling it directly from wherever it is?
|
Aliases aren't in the path. They're in the environment.
Run the command alias with no arguments to get a list of currently defined aliases. Or run the command type temp to verify that temp really is aliased. Are you calling the script from the command line? From cron? Via SSH? What error message do you get? |
The type temp command gives me this output
Code:
temp is aliased to `cat /home/jason/Desktop/scripts/test' Code:
var2=$(temp | awk '{print $4}') Code:
line 6: temp: command not found |
That's curious. I just tried a very similar thing here and it worked.
Are you executing the var2 assignment from the command line? Or is it in a script? If in a script, are you calling it from the command line? What's even more curious is the reference to line 6 when 'temp' has but one line. It makes me wonder if there is some other 'temp' script somewhere that's getting called instead. |
It seems to me that aliases cannot be inherited from the environment into shell scripts. However you can use aliases in a shell script if the alias definition is in your $HOME/.bashrc file and if you make your shell act as a login shell (in this case the .bashrc file is sourced). For example
Code:
#!/bin/bash -l |
All times are GMT -5. The time now is 03:01 AM. |