我试图运行一个命令并将其存储在一个variables中。
length=`last | grep foouser | wc -l`
它工作正常,但是当我添加一个variables的命令打破。
value=$1 length=`last | grep $value | wc -l`
我怎样才能得到这个第二个例子通过acceptomgvariables工作?
你实际上并不需要wc
:
length=$(last | grep -c "$value")
你可以改进变量名称
num_logins=$(last | grep -c "$username")
你应该适当地引用你的变量。 如果它们包含空格,脚本可能会中断:
value="$1" length="$(last | grep "$value" | wc -l)"