OS:Yocto
我想将shell输出分配给一个variables,
但是得到错误“test.sh:line 3:out:command not found”。
怎么做 …?
这是我的代码:
#!/bin/bash out = "$(ls /dev/ | grep "tty" | wc -l)" echo"$out"
我试过这个: 如何设置一个variables来自Bash命令的输出?
空格很重要。
#!/bin/bash out="$(ls /dev/ | grep "tty" | wc -l)" echo "$out"
当你给变量赋值的时候,不要在“=”之前和之后保留Whitespace,在bash中产生错误
#!/bin/bash out="$(ls /dev/ | grep "tty" | wc -l)" echo"$out"
尝试使用=
左右空格,即out="$(ls /dev/ | grep "tty" | wc -l)"