Review your favorite Linux distribution.
Go Back > Blogs > linux-related notes
User Name


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

Make a bash script recognize bash aliases

Posted 05-12-2015 at 04:16 PM by the dsc
Updated 05-12-2015 at 04:22 PM by the dsc (mismatched tags)

Say, if you have a script that would take as a parameter something that you have aliased, it wouldn't work.

I mean:

$ ./ myalias whatever else
/home/dude/scripts/ line 3: myalias: command not found

In order to make it work, the said script must include:

shopt -s expand_aliases
source ~/.bash_aliases
(Or wherever your aliases are set, which would preferably be a file with only them, I guess... not sure how it would turn out if they were on .bashrc...)

That's according to this:

I can't find an anchor-link to the specific answer, which currently is the second most voted, and, since it may change I guess, the link is to the "revisions page" to that answer.

Warning: If one has within that script commands that are aliased in some way that's not particularly useful or potentially hazardous within the script, I think it would require to explicitly use the command with the full path, within the script. I'm not sure.

Say, if you have "ls" aliased as "ls --nifty-neat-human-readable-output", but the script is parsing a cruder/rawer/simpler output of "ls", it would mess up your parsing. (It's said that ls shouldn't be parsed to begin with, but that's not the point).
Posted in Uncategorized
Views 1044 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 10:33 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration