Spyke
nostupidquestions·No Stupid QuestionsbyRudee

Can Bash aliases be nested?

For example if I have a setup like:

 alias llaa = pwd && ll'''

Will the second command work, or would I have to set it up in a more verbose manner (like ```alias llaa = pwd && ls -la```)
View original on lemmy.ml

Should work. Just try it out and see if you get what you want. I tried:

alias llaa='pwd && ll'

then ran llaa and it did what I expected, current directory and the output of ls -al which is aliased.

9
lemmy.world

I think you don't want the spaces around the= sign. Preferred over alias is function llaa { ... }. Alias is for backwards compatibility.

7
feddit.org

Preferred over alias is function llaa { ... }. Alias is for backwards compatibility.

Again what learned. What is wrong with having spaces around the equals sign, though?

1
solrizereply
lemmy.world

I think it might not work with the spaces. But if it does, then you are fine.

2

Ah, obviously you're right and bash is less tolerant to spaces than I've had in my mind:

You can declare aliases that will last as long as your shell session by simply typing these into the command line. The syntax looks like this:
alias alias_name="command_to_run"
Note that there is no spacing between between the neighbor elements and the equal sign. This is not optional. Spaces here will break the command.

https://www.digitalocean.com/community/tutorials/an-introduction-to-useful-bash-aliases-and-functions

4

You reached the end

Can Bash aliases be nested? | Spyke