I tried to assign variable a
in for-loop:
JavaScript
x
#!/bin/bash
for file in `ls`
do
a = $file
done
But when I run, it gave error:
JavaScript
line 5: a: command not found
Why did it give error? How to assign variable a
?
Advertisement
Answer
There can be no spaces on both sides of the equal sign when defining variables in the Shell.
It should be:
JavaScript
a=$file