The other day I was trying to create an alias in Linux for a repetitive bunch of commands. An alias is a name that is translated as another name or command (or a set of commands).
So, I tried to create the alias in the following manner:
alias my_short_command = "command 1; command 2 && command 3; command 4"
And it threw me the following error:
zsh: bad assignment
If you are a regular user of Linux command line, you must have identified the error on the previous command. But I was preoccupied with my program in C++ and I did not notice the obvious error here.
In fact, I thought it to be an error with the way I used the combination of error for the alias. So, I fiddled for a couple of minutes and just to make sure what I was doing wrong, tried this command:
alias l = "ls -lrt"
Now, I was certain that there was no error with the commands this time but I git the same result as above:
zsh: bad assignment
And that’s when I realized my mistake. You see, I have been working a lot with C++ and was following the standard of using spaces before and after the assignment operator (=). And that is what I used here as well. And Shell, it does not like the wastage of “space”.
I removed the extra white spaces before and after the = and voilà! There it worked, like a charm.
In fact, the same error can be encountered with the export command as well. This taught me a lesson to not waste white spaces while dealing with shell scripts and Linux commands. It’s not the same as writing programs in other languages.
I hope if you would not have to waste your time with this problem if you mind those spaces before and after the equals sign.