Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

concatenating aliases in linux shell

Tags:

alias

linux

shell

I would like to concatenate aliases. So for example, if I have the following:

alias aliasone="cat"
alias aliastwo="/etc/passwd"

I would like to be able to type in the shell something like "aliasone+aliastwo" and then the following command will be executed:

cat /etc/passwd

Can this be done?

Thanks!

like image 450
Tal Avatar asked Aug 23 '26 17:08

Tal


2 Answers

Aliases are only for command substitution. If you want to have shorthand for arguments, use shell variables.

file=/etc/passwd
cat "$file"
like image 97
John Kugelman Avatar answered Aug 25 '26 13:08

John Kugelman


Simply remove the "alias" from the second line. That is:

alias aliasone="cat"
folder="/etc/passwd"

And then you can write:

aliasone $folder

The problem is that alias evaluate commands; but in the second alias there is no command. In the case of a parameter is better to use a variable. If you have a more particular situation (e.g. you are are inside a script) tell us so we can give a better solution.

like image 27
RafaelCaballero Avatar answered Aug 25 '26 12:08

RafaelCaballero



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!