I know it for one command but how to work with a sequence?


2 Answers 2


I put this as an answer, because cannot format it in the comment properly

foo() {
   echo foo
   echo bar

> foo

Imho, you have more freedom with a function than with alias. At least you can format it properly.

Advanced Bash-Scripting Guide

In a script, aliases have very limited usefulness. It would be nice if aliases could assume some of the functionality of the C preprocessor, such as macro expansion, but unfortunately Bash does not expand arguments within the alias body. [2] Moreover, a script fails to expand an alias itself within "compound constructs," such as if/then statements, loops, and functions. An added limitation is that an alias will not expand recursively. Almost invariably, whatever we would like an alias to do could be accomplished much more effectively with a function.

  • U Rocks!!! @UVV
    – sashi
    Nov 27, 2014 at 9:13
  • @UVV It doesn't create an alias. That is just a function which runs some commands when you call it. Nov 27, 2014 at 9:34
  • @KasiyA as I said, imo with a function you have more flexibility. I extended my answer.
    – UVV
    Nov 27, 2014 at 9:49
  • 1
    @KasiyA As I see it, he wants to run two commands consequently. I suggested just another way to do this.
    – UVV
    Nov 27, 2014 at 10:11
  • 3
    @KasiyA: How is a function not as flexible as an alias? Generally, a function is far more flexible than an alias. Eg, a function can accept arguments. Aliases are fine for simple things, but otherwise the last sentence quoted above from the Bash man applies. Certainly, the question asked about aliases, and to be complete UVV should have shown how to do it with an alias, and then given a function-based answer, with the support of that Bash man quote.
    – PM 2Ring
    Nov 27, 2014 at 10:49
start cmd:> alias foo="echo foo; echo bar"
start cmd:> foo
  • A function could also be used instead of alias.
    – UVV
    Nov 27, 2014 at 9:05
  • can u explain that @UVV
    – sashi
    Nov 27, 2014 at 9:06
  • 4
    May be better as alias foo='{ echo foo; echo bar; } or even better as a function (to avoid confusion if one runs foo bar) as otherwise you'd get surprising results when doing cmd || foo or foo | bar or foo > file for instance. Nov 27, 2014 at 10:51

Not the answer you're looking for? Browse other questions tagged .