bash: command works at command line, but not via an alias
Could someone kindly explain these results, why the command works at the command line, but fails when an alias is used.
Code:
~ $ alias fs |
Aliases don't accept positional parameters (arguments). What you're really issuing is:
Code:
ls -hsR /media/3tb|grep -i "" "wild at heart" |
Quote:
|
To be completely clear, an alias is a simple command name substitution. If the first word of the line you run matches a defined alias, then it's replaced with the contents of the alias and the modified command line is executed.
Code:
$ alias echoit='echo foo' In short, you can't build arbitrary commands with aliases, you can only use them to replace the first word with a different string. The rest of the contents of the line remain where they started. Note that there are tricks you can use to do some really clever things with aliases, but it's generally not recommended to do so. aliases were really designed to be simple command shortcuts. Use functions for more complex stuff. BTW, colucix's explanation is not quite right in one respect. Variable substitutions are still made. If the parent shell just happens to have a $1 value set, then it will show up in the final command. Code:
$ alias echoit='echo $1' |
All times are GMT -5. The time now is 01:38 AM. |