我需要自学 bash 脚本。我正在阅读这本电子书,它有以下代码:
#!/bin/bash
# hello.sh
# This is my first shell script!
declare -rx SCRIPT="hello.sh"
declare -rx who="/usr/bin/who"
declare -rx sync="/bin/sync"
declare -rx wc="/usr/bin/wc"
# sanity checks
if test -z "$BASH" ; then
printf "$SCRIPT:$LINENO: please run this script with the BASH shell\n" >&2
exit 192
fi
if test ! -x "$who" ; then
printf "$SCRIPT:$LINENO: The command $who is not available - aborting\n" >&2
exit 192
fi
if test ! -x "$sync" ; then
printf "$SCRIPT:$LINENO: the command $sync is not available - aborting\n">&2
exit 192
fi
if test ! -x "$wc" ; then
printf "$SCRIPT:$LINENO: the command $wc is not available - aborting\n" >&2
exit 192
fi
USERS = `$who | $wc -l`
if [ $USERS -eq 0 ] ; then
$sync
fi
exit 0
当我运行它时,我收到以下错误:
hello.sh: line 32: USERS: command not found
hello.sh: line 33: [: -eq: unary operator expected
我真的不知道我做错了什么。我是否不允许以这种方式将用户分配给命令行的输出?如果我在命令行中运行该行,它也不起作用。有任何想法吗?
谢谢