Fixing "zsh: bad assignment" error in Linux
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:
And it threw me the following error:
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:
Now, I was certain that there was no error with the commands this time but I git the same result as above:
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.
I hope you would not have to waste your time with this problem if you mind those spaces before and after the equals sign.
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 🕵️♂️
How To Fix Ubuntu Update Error: Problem With MergeList
How to fix "repository is not valid yet" error in ubuntu linux, how to use nightlight feature in linux mint to save your eyes at night, fixing 'shell script opening in text editor' in ubuntu and other linux, enabling bluetooth on arch linux, it's foss.
Making You a Better Linux User
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to It's FOSS.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.
Stack Exchange Network
Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Cannot export variable thanks to a script with zsh
I have written a script export-zsh to set new variables in zsh
Errors occur if I run it
When I execute each command individually, it lead to no errors:
when I run source ~/.zshrc , there are no errors, so I don't think it should be directly related to my ~/.zshrc content but I give it below to be sure.
You script is executed by Bash. Reading your .zshrc with Bash doesn't work but gets you errors for all the Zsh specific stuff.
Your script runs in its own subshell. As settings, environment variables and such are not exported back to the calling shell ascript will not work here. Use a function instead and put it in your .zshrc :
You must log in to answer this question.
Not the answer you're looking for browse other questions tagged zsh ..
- The Overflow Blog
- What language should beginning programmers choose?
- Supporting the world’s most-used database engine through 2050
- Featured on Meta
- New Focus Styles & Updated Styling for Button Groups
- Upcoming initiatives on Stack Overflow and across the Stack Exchange network
- AI-generated content is not permitted on Ask Ubuntu
- Let's organize some chat workshops
Hot Network Questions
- Do "tinker" and "tinkerer" imply "unskillful"?
- How to select all the vertices on one side of an edge loop?
- Passport Control at Frankfurt airport
- Was Deuteronomy 18:15, interpreted messianically in Judaism?
- Continuous addition and multiplication on Euclidean space (dimension > 2) making it into a field?
- What is a Pillycoddian gesture?
- Why does set-theoretic union and intersection operate on reverse logic?
- ANOVA vs Kruskal Wallis - Small sample size
- Why protest against the war in Gaza on the campus of Columbia University?
- A short fantasy fiction in the London Tube (not the novel "Neverwhere")
- Finding food on the run
- How to disconnect stainless steel and threaded galvinized piping connection
- Can a copy-pasting a word definition from dictionary sites cause a copyright issue?
- Can you work on Chol Ha'moed if you'll be fired otherwise?
- Is it a cartesian product?
- White dwarf supernova luminosity
- Jawohl answer when someone knocks at the door
- Did Tolkien invent Bilbo saving the Dwarves but forgetting about himself?
- Shebang can reference a script in Linux
- Is there such a thing as a "physical" fractal?
- Why there is huge gap between allocated and used size in a database
- Why does the frequency sampling method for FIR filter design operate in this manner?
- Why is one process ps command showing spaces around a directory instead of slashes?
- How to make a sign language that only uses three fingers
Stack Exchange Network
Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
export -f equivalent in zsh
I just joined a new team and the environment setup script uses export -f commands inside it. Even though there's a bash shebang at the top, it seems like the export command being called is the one from zsh and so the -f option doesn't work. Is there a way to fix this or am I obligated to use bash?
- linux - How to export a function in ksh ? Without global declaration or using autoload - Stack Overflow – DavidPostill ♦ Jan 8, 2020 at 19:20
2 Answers 2
Zsh doesn't support exporting functions and very likely never will. It is not a clever feature as was made plain by the shell shock bug a few years ago. Function autoloading is a better approach.
Environment setup files typically have to be sourced - inlined in an existing shell instance so the shebang is ignored. It'd be better to persuade your team to stick to portable features. Functions could be but aside in a directory and sourced for bash or autoloaded for zsh.
Or if really necessary create a temporary function wrapper for export to ignore -f, use disable export source the bash setup and then reenable zsh's export.
If you have ended up here because Google decided this was the "best result" the accepted answer is more opinionated than helpful. I was going to mark this as a duplicate, but the answer found was on unix stackexchange. @davidpostill also posted this in the question, but I typically cruise down to the answer section immediately. The real answer . It also contains a link to the wiki about shell shock bug from 2014 that is still not fixed.
You must log in to answer this question.
Not the answer you're looking for browse other questions tagged bash zsh ..
- The Overflow Blog
- What language should beginning programmers choose?
- Supporting the world’s most-used database engine through 2050
- Featured on Meta
- New Focus Styles & Updated Styling for Button Groups
- Upcoming initiatives on Stack Overflow and across the Stack Exchange network
- Google Cloud will be Sponsoring Super User SE
Hot Network Questions
- Product map on topological group measurable?
- Does a WIPO patent supersede a US patent?
- Why is the aperture door of the Hubble Space Telescope so weirdly shaped?
- Employer asking to open a business bank account. Is this job a scam or legit?
- basic rock paper and scissors v2
- Continuous addition and multiplication on Euclidean space (dimension > 2) making it into a field?
- Why there is huge gap between allocated and used size in a database
- If Alice measures a qubit and doesn't tell Bob the result, what's Alice's state from Bob's perspective?
- When submitting a letter to an agent for publication of a novel, what does it mean to say that your manuscript is "complete"?
- How to make an infinite repeating projection in qgis?
- Do "tinker" and "tinkerer" imply "unskillful"?
- Importing Specific Data from a Text File
- Can you work on Chol Ha'moed if you'll be fired otherwise?
- Both disc brakes stopped working after severe weather: No pressure when levers are pulled
- Finding food on the run
- What features should a ceiling fan have so I can switch light and fan separately?
- Does an upcast Banishment send the targets to the same place if they share a native plane?
- Shebang can reference a script in Linux
- How to get the analytical form of a solution to an algebraic equation?
- Why is the FFT output divided by the data length?
- Are there any languages where conditions are not first-class expressions?
- Can an undergraduate student be penalized for exceeding what is expected of a work?
- Did Tolkien invent Bilbo saving the Dwarves but forgetting about himself?
- How to reconcile the Gospel of John to Revelation regarding the perishability of those condemned to hell
Navigation Menu
Search code, repositories, users, issues, pull requests..., provide feedback.
We read every piece of feedback, and take your input very seriously.
Saved searches
Use saved searches to filter your results more quickly.
To see all available qualifiers, see our documentation .
- Notifications
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: ZSH_HIGHLIGHT_STYLES: assignment to invalid subscript range #359
Lordanakun commented Sep 2, 2016
phy1729 commented Sep 2, 2016
Sorry, something went wrong.
danielshahaf commented Sep 2, 2016 via email
- 👎 28 reactions
- 😕 2 reactions
flamendless commented Jul 11, 2017
Danielshahaf commented jul 11, 2017, flamendless commented jul 12, 2017, danielshahaf commented jul 12, 2017.
hamedarman commented Jul 26, 2017
TheBabu commented Aug 4, 2017
saikiran-siriki commented Sep 30, 2017
Danielshahaf commented sep 30, 2017, danielshahaf commented sep 30, 2017 via email, danielshahaf commented oct 1, 2017 via email, thebabu commented oct 4, 2017.
AaronFlower commented Mar 18, 2018
- 👍 13 reactions
- ❤️ 6 reactions
danielshahaf commented Mar 18, 2018
bkjoel commented Apr 19, 2019
- 👍 3 reactions
mahiki commented Apr 19, 2021
Danielshahaf commented apr 19, 2021.
No branches or pull requests
IMAGES
VIDEO
COMMENTS
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 ...
Open the file /Users/me/.zshrc [this is the file where you were trying to add the path for Python] Look for the line that is missing a '', and add that ''. [most likely it's going to be the line you added with Python], so look there first. Save your file and exit.
proper assignment; now the value of foo is bar (note the leading space) foo-x=bar. command foo-x=bar (because foo-x is not a valid name for a shell variable) This is not specific to Zsh. The POSIX shell ( sh) and POSIX-compliant shells behave this way. Zsh (while not being POSIX-compliant in general) also follows. Share.
This is similar to #263 but I get a different error: (eval):15: bad assignment As a result, all plugin aliases are gone. I'm using the zsh calc plugin, which aliases the =. When I remove this plugin, I get no errors and got all plugin al...
If you run your script with -x (both bash and zsh) you will see that the $(...) code gets interpreted/parsed differently.This is because, as stated in the FAQ, word splitting in zsh is backwards/bash/sh incompatible.. You can use SH_WORD_SPLIT to address this difference.. Ok, so it is not a word split problem as we have a command substitution, quoting the docs again:
Standards checklist: The PR title is descriptive. The PR doesn't replicate another PR which is already open. I have read the contribution guide and followed all the instructions. The code follows the code style guide detailed in the wiki. The code is mine or it's from somewhere with an MIT-compatible license. The code is efficient, to the best of my ability, and does not waste computer resources.
From the zsh manual regarding the typeset builtin (which local is a special case of): Unlike parameter assignment statements, typeset 's exit status on an assignment that involves a command substitution does not reflect the exit status of the command substitution.
Alternatively, you can keep your aliases in ~/.aliases file itself which can be portable across systems but then add below lines at the end of ~/.zshrc to include all of them #...more zsh config above if [ -f ~/.aliases ]; then . ~/.aliases fi
First, open the .zshrc file: nano ~/.zshrc. Jump to the end of the line in nano using Ctrl + / and add the alias in following syntax: alias -s [extension]="preferred-tool". I want to add the nano as a suffix to open .txt, VSCode for .py and .json files so I will add the following: alias -s txt=nano. alias -s py=code.
Your script runs in its own subshell. As settings, environment variables and such are not exported back to the calling shell ascript will not work here. Use a function instead and put it in your .zshrc: export-zsh(){ echo "export $@">> .zshrc source .zshrc }
It'd be better to persuade your team to stick to portable features. Functions could be but aside in a directory and sourced for bash or autoloaded for zsh. Or if really necessary create a temporary function wrapper for export to ignore -f, use disable export source the bash setup and then reenable zsh's export. Share. Improve this answer.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window.
1. aliases already exists as an associative array containing all your shell aliases. Call the variable something else. It may alias help to declare your variable local, for a normal array: local -a compl_aliases. The bad set of key/value pairs usually indicates that you have an odd number of elements when doing an associative array assignment.
EDIT 2. Output of zsh -vn .zshrc. I cleaned up my .zshrc file to this: When I start my shell I see both OK and OK2, no errors show. But here's the output of zsh -vn .zshrc. # /etc/zsh/zshenv: system-wide .zshenv file for zsh(1). # This file is sourced on all invocations of the shell. # are skipped.
Your i variable has likely been declared as integer or float by any one of integer i, typeset -i i, float i, typeset -E i or typeset -F i.. Then when you try to assign /houdi/lookup, the shell attempts to interpret it as an arithmetic expression and complains because the first / division operator there is missing its first operand.. Check with: typeset -p i