On a Mac, how can I group together commands I want run into a alias?
In my .bash_profile I have created alias to commands that I run often.
What if I want to group together multiple commands together, and they should run in serial one after the other.
How would I do this?
You can create a function instead of an alias:
function foo {
cat somefile.txt
rm anotherfile.txt
}
You can even pass parameters (foo somefile.txt
) and use them as arguments to the commands (e.g. cat $1
for the first argument).
This approach is more flexible than creating an alias
.
Concatenate them with &&
, for example
cat somefile.txt && rm anotherfile.txt
Note that chaining it this way the commands depend on the exit state of their preceding one, so if any command would fail, the execution of the whole line would stop at that point.
Separate them with ;
, for example
cat somefile.txt; rm anotherfile.txt