有关信息,我在 solaris 9 上,使用 bash 脚本。手动运行脚本工作正常,但通过 cron,他无法通过第一次验证:
if [ `/usr/bin/echo $MACHTYPE | grep -i "solaris"` ];then
我尝试了几十种变化。但似乎没有一个工作。我可以跳过那部分,但稍后我会遇到类似的问题,这个 if 语句很有趣,因为它包含一个使用系统变量的命令。我尝试了另一个版本,将输出与字符串进行比较(可能更难?)但我被卡住了。
如果有人可以说明使用什么以及在哪里使用:( [ ' " 因为有时 [[ 无法识别。所有的变化都是基于我在这里和其他地方找到的。似乎格式化的可能性很大。(我离开了出另一个'然后回声.. fi')
[mvf@odin:/usr/mvf/bin/scripts] $ if ['/usr/bin/echo $MACHTYPE == "solaris"']
> then echo "hello"
> fi
bash: [/usr/bin/echo $MACHTYPE == "solaris"]: No such file or directory
[mvf@odin:/usr/mvf/bin/scripts] $ if ['/usr/bin/echo $MACHTYPE == 'solaris'']
bash: [/usr/bin/echo $MACHTYPE == solaris]: No such file or directory
[mvf@odin:/usr/mvf/bin/scripts] $ if ["/usr/bin/echo $MACHTYPE == 'solaris'"]
bash: [/usr/bin/echo solaris == 'solaris']: No such file or directory
[mvf@odin:/usr/mvf/bin/scripts] $ if ["$MACHTYPE == 'solaris'"]\
bash: syntax error near unexpected token `fi'
[mvf@odin:/usr/mvf/bin/scripts] $ if ["$MACHTYPE == 'solaris'"]
bash: [solaris == 'solaris']: command not found
[mvf@odin:/usr/mvf/bin/scripts] $ if ['$MACHTYPE == 'solaris'']
bash: [$MACHTYPE == solaris]: command not found
[mvf@odin:/usr/mvf/bin/scripts] $ if ['$MACHTYPE == solaris']
bash: [$MACHTYPE == solaris]: command not found
[mvf@odin:/usr/mvf/bin/scripts] $ if ["$MACHTYPE == solaris"]
bash: [solaris == solaris]: command not found
[mvf@odin:/usr/mvf/bin/scripts] $ if [["$MACHTYPE" == "solaris"]]
bash: [[solaris: command not found
[mvf@odin:/usr/mvf/bin/scripts] $ if [[$MACHTYPE == solaris]]
bash: [[solaris: command not found
[mvf@odin:/usr/mvf/bin/scripts] $ if [["$MACHTYPE" == solaris]]
bash: [[solaris: command not found
[mvf@odin:/usr/mvf/bin/scripts] $ if [["/usr/bin/echo $MACHTYPE" == solaris]]
bash: [[/usr/bin/echo solaris: No such file or directory
[mvf@odin:/usr/mvf/bin/scripts] $ if [[($MACHTYPE) == solaris]]
bash: syntax error near unexpected token `[[($MACHTYPE)'
[mvf@odin:/usr/mvf/bin/scripts] $ if [[($MACHTYPE) == solaris]]
bash: syntax error near unexpected token `[[($MACHTYPE)'
[mvf@odin:/usr/mvf/bin/scripts] $ if [["/usr/bin/echo $(MACHTYPE)" == solaris]]
bash: MACHTYPE: command not found
bash: [[/usr/bin/echo : No such file or directory
[mvf@odin:/usr/mvf/bin/scripts] $ if [["$(MACHTYPE)" == solaris]]
bash: MACHTYPE: command not found
bash: [[: command not found
[mvf@odin:/usr/mvf/bin/scripts] $ if ["$(MACHTYPE)" == solaris]
bash: MACHTYPE: command not found
[: missing `]'
[mvf@odin:/usr/mvf/bin/scripts] $ if [$(MACHTYPE) == solaris]
bash: MACHTYPE: command not found
[: missing `]'
[mvf@odin:/usr/mvf/bin/scripts] $ if [[ $(echo $MACHTYPE) == solaris]]; then
bash: [[: command not found
[mvf@odin:/usr/mvf/bin/scripts] $ if (( $(echo $MACHTYPE) == solaris)); then
bash: solaris: command not found
[mvf@odin:/usr/mvf/bin/scripts] $ if (( $(echo /$MACHTYPE) == solaris)); then
> echo "hello"
> fi
bash: /solaris: No such file or directory
[mvf@odin:/usr/mvf/bin/scripts] $ if (( $(echo /$MACHTYPE) == solaris)); then
>
> fi
bash: syntax error near unexpected token `fi'
[mvf@odin:/usr/mvf/bin/scripts] $ if (( $($MACHTYPE) == solaris)); then
bash: solaris: command not found
bash: ==: command not found
[mvf@odin:/usr/mvf] $ if (( $(echo \$MACHTYPE) == solaris)); then
bash: $MACHTYPE: command not found
[mvf@odin:/usr/mvf] $ if (( $('echo \$MACHTYPE') == solaris)); then
> echo "hello"
> fi
bash: echo \$MACHTYPE: command not found
bash: ==: command not found
[mvf@odin:/usr/mvf] $ if (( $('echo $MACHTYPE') == solaris)); then
bash: echo $MACHTYPE: command not found
bash: ==: command not found
[mvf@odin:/usr/mvf] $ if (( $('/usr/bin/echo $MACHTYPE') == solaris)); then
bash: /usr/bin/echo $MACHTYPE: No such file or directory
bash: ==: command not found
[mvf@odin:/usr/mvf] $ if (( $(/usr/bin/echo $"MACHTYPE") == solaris)); then
bash: $MACHTYPE: command not found