本文介绍了错误两个脚本:"一元运算符预期"和"整前pression预期"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了两个脚本,试图做同样的动作两种不同的方式,但我得到的错误我每次运行这些时间。请请求您的帮助纠正我的脚本和提高我的知识和。所有我试图做VPS建立在一个脚本。下面的两个脚本将在其中得到的错误,它部分各一次。

1)脚本来设置通过的cPanel XML的API主机名在OpenVZ的节点的VPS

猫vpstest.sh

 #/斌/庆典
hostname_status =`卷曲-sku根:PASSWORDHEREHTTPS://ip.x.x.x:2087 / XML的API / sethostname主机= server.domain.com| awk的-F[<>]'/状态/ {打印$ 3}'|头-n1`
    如果[$ hostname_status -eq 1];然后
      回声主机名集
    其他
      回声失败设置主机名
    科幻

输出:

 #./vpstest.sh
./vpstest.sh:3号线:[:当量:一元运算符预期
失败的主机名设置


2)脚本设置通过命令行的主机名在OpenVZ的节点

猫vpstest1.sh

 #!/斌/庆典
hostname_status =`vzctl设置containerID --hostname server.domain.com --save`
    如果[$ hostname_status-eq 1];然后
      回声主机名集
    其他
      回声失败设置主机名
    科幻

输出:

 #./vpstest1.sh
./vpstest1.sh:3号线:[:保存到/etc/vz/conf/containerID.conf CT配置:整数EX pression预期
失败的主机名设置


有人能帮助清除这些错误?


解决方案

首先,的输出vzctl设置containerID --hostname server.domain.com --save 似乎而 -eq 只提供给做整数值之间的比较不是一个整数值。

这可以解释以下错误:

Then, you should read this reminder about the necessity (or not) to protect your variables with double quotes.

This would explain the following error, you could use something like :

If you want to check the status of a command :

command >/dev/null 2>&1 && echo "success" || echo "fail"
# or
if command >/dev/null 2>&1; then
    echo "success"
else
    echo "fail"
fi

You could also check the variable $? which correspond to the status of the previous command (0 when that command success or another integer value which is 1 in most of cases, or more).

这篇关于错误两个脚本:"一元运算符预期"和"整前pression预期"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 02:48
查看更多