页面“Shell date用法”与“Shell too many arguments”之间的差异
(页面间的差异)
跳到导航
跳到搜索
小 (导入1个版本) |
docker>Evan |
||
第1行: | 第1行: | ||
− | + | =too many arguments= | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<pre> | <pre> | ||
− | + | Question: | |
− | + | + webcode='[Errno 111] Connection refused' | |
− | + | + '[' '[Errno' '111]' Connection refused -eq 200 ']' | |
− | + | /data/update/sh/readup.sh: line 27: [: too many arguments | |
− | + | Solve Solutions: | |
− | + | if [ $webcode -eq 200 ] 变为 | |
− | |||
− | |||
− | + | webcode=` /data/mon/monitor_http.py http://47.106.6.9:80/xtwlztdj_read_interface/cmd/version` | |
− | + | if [ "$webcode" -eq "200" ] | |
+ | then | ||
+ | echo "read is sucess" | ||
+ | fi | ||
+ | Cause: | ||
+ | 养成将所有字符串自变量用双引号括起的习惯,将除去很多类似的编程错误。 | ||
− | + | 如果环境变量没放在双引号中,那么bash 认为条件中的自变量过多。 | |
− | + | 可以用双引号将字符串自变量括起来消除该问题。 | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | 看来是要养成将所有字符串自变量用双引号括起的习惯,将除去很多类似的编程错误。 | |
</pre> | </pre> | ||
− | == | + | =see also= |
− | + | [https://blog.csdn.net/wang_cir/article/details/6120101 关于Shell 脚本中的"[: too many arguments"错误] | |
− | |||
− | |||
− | |||
− | [https://blog.csdn.net/ | ||
− | + | [[category:shell]] |
2018年10月31日 (三) 02:42的版本
too many arguments
Question: + webcode='[Errno 111] Connection refused' + '[' '[Errno' '111]' Connection refused -eq 200 ']' /data/update/sh/readup.sh: line 27: [: too many arguments Solve Solutions: if [ $webcode -eq 200 ] 变为 webcode=` /data/mon/monitor_http.py http://47.106.6.9:80/xtwlztdj_read_interface/cmd/version` if [ "$webcode" -eq "200" ] then echo "read is sucess" fi Cause: 养成将所有字符串自变量用双引号括起的习惯,将除去很多类似的编程错误。 如果环境变量没放在双引号中,那么bash 认为条件中的自变量过多。 可以用双引号将字符串自变量括起来消除该问题。 看来是要养成将所有字符串自变量用双引号括起的习惯,将除去很多类似的编程错误。