1

The bash manual says for alias,

There is no mechanism for using arguments in the replacement text, as in csh. If arguments are needed, a shell function should be used (see Section 3.3 [Shell Functions], page 17).

What do the two sentences mean?

"using arguments in the replacement text" doesn't seem to mean the following, which succeeds

$ alias foo="echo bac" 
$ foo
bac
$ foo hello
bac hello
| improve this question | | | | |
  • That's not using an argument. The macro was simply replaced with the expansion, and the argument is still there after it. But there's no way to substitute an argument into the middle of the command. – Barmar Dec 19 '16 at 5:35
1

I suppose the wording is not perfect, unless you take it very literally. Bash does not replace any aliased text with arguments; it will append arguments to the text, as you saw. This is in contrast with CSH aliases which expands arguments inside the replacement text.

The second sentence, IMHO, stems from the above restriction, and encourages the more-flexible function definitions over the simplistic aliases.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.