Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
コマンドを実行して変数に保存しようとしています。
length=`last | grep foouser | wc -l`
正常に動作しますが、コマンドに変数を追加すると壊れます。
value=$1 length=`last | grep $value | wc -l`
変数を受け入れて、この 2 番目の例を機能させるにはどうすればよいですか?
実際には必要ありませんwc:
wc
length=$(last | grep -c "$value")
変数名を改善できます
num_logins=$(last | grep -c "$username")
変数を適切に引用する必要があります。スペースが含まれていると、スクリプトが壊れる可能性があります。
value="$1" length="$(last | grep "$value" | wc -l)"