Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I tried to assign variable a in for-loop:
a
#!/bin/bash for file in `ls` do a = $file done
But when I run, it gave error:
line 5: a: command not found
Why did it give error? How to assign variable a?
$()
ls
=
touch =
touch
There can be no spaces on both sides of the equal sign when defining variables in the Shell.
It should be:
a=$file
Add a comment
You need remove spaces i.e.
a = $file
must be
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
$()over backticks and generally avoid parsing output ofls. Learn to use globbing a.k.a. filename expansion.a, with=as first argument. Similarily,touch =would create a file named=and not create a variable namedtouch.