Fixing "zsh: bad assignment" error in Linux

Read to find out what caused the zsh: bad assignment error in Linux and how you can fix it.
Warp Terminal

The other day I was trying to create an alias in Linux for repetitive 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 the 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 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 or any other variable assignments in the shell. There should not be spaces before and after equals sign.

This taught me a lesson to not waste white space while dealing with shell scripts and Linux commands. Itโ€™s not the same as writing programs in other languages.

I would add this tiny learning lesson to my list of things to know about the Linux terminal.

19 Basic But Essential Linux Terminal Tips You Must Know
Learn some small, basic but often ignored things about the terminal. With the small tips, you should be able to use the terminal with slightly more efficiency.

I hope you would not have to waste your time with this problem if you mind those spaces before and after the equals sign.

About the author
Abhishek Prakash

Abhishek Prakash

Created It's FOSS 11 years ago to share my Linux adventures. Have a Master's degree in Engineering and years of IT industry experience. Huge fan of Agatha Christie detective mysteries ๐Ÿ•ต๏ธโ€โ™‚๏ธ

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world


Great! Youโ€™ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.