gpt4 book ai didi

linux - bash 脚本将输出分配给变量失败

转载 作者:可可西里 更新时间:2023-11-01 11:48:53 26 4
gpt4 key购买 nike

操作系统:Yocto

我想将 shell 输出分配给一个变量,

但出现错误“test.sh: line 3: out: command not found”。

怎么做...?

这是我的代码:

#!/bin/bash

out = "$(ls /dev/ | grep "tty" | wc -l)"
echo"$out"

我试过这个: How to set a variable to the output from a command in Bash?

最佳答案

空格很重要。

#!/bin/bash

out="$(ls /dev/ | grep "tty" | wc -l)"
echo "$out"

关于linux - bash 脚本将输出分配给变量失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32174178/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com