[英]Cannot assign variable in for-loop in shell script
I tried to assign variable a
in for-loop:我试图在for循环中分配变量
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
?如何分配变量
a
?
There can be no spaces on both sides of the equal sign when defining variables in the Shell.在 Shell 中定义变量时,等号两边不能有空格。
It should be:它应该是:
a=$file
You need remove spaces ie你需要删除空格,即
a = $file
must be一定是
a=$file
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.