for i in 1 2 3 4; do echo $i; done 2、测试for的自增长的循环: #!/bin/bash for ((i=1; i<=5; i++)) do echo $i; done 如果会报错,没有则跳过: Syntax error: Bad for loop variable 原因:代码对于标准bash而言没有错,因为Ubuntu为了加快开机速度,用dash代替了传统的bash,是dash在捣鬼。
shell中的for循环出现语法错误(syntax error: bad for loop variable) 出现这种错误是因为有些linux系统默认会使用ash进行编译shell脚本,我的机器就是这样,但是我写的脚本是应该用bash执行的。虽然我在开头注明了#!/bin/bash,好像它还是默认去找了ash,真是让人无奈。上网搜索了一下,找到两种解决方案:1、修改脚本 ...
add.sh: 4: Syntax error: Bad for loop variable 代码没有错误,Ubuntu为了加快开机速度,用dash取代bash。 解决的方法:取消dash,使用bash: sudo dpkg-reconfigure dash 选择No选项。
linux shell下某些命令失效,例如< 、 >等符号,例如 : 报错 Syntax error: Bad for loop variable 在终端下执行这个:选择 否 sudo dpkg-reconfigure dash
发帖说明:http://www.fecshop.com/topic/624 如果是你自己的流水笔记,请到自己的博客里面发 hetao•#2•6年前 0 个赞 这个博客并不是我的,只是本着同样的问题别人也可能遇到另外修改脚本语法也是一种方案 hetao•#3•6年前 0 个赞 当然如果本论坛只接受bug报告,不接受fecshop有关的交流我不说什...
: 4: Syntax error: Bad for loop variable 解决办法:sudo dpkg-reconfigure dash 在选择项中选No Loong:/home# sudo dpkg-reconfigure dash [: 88: false: unexpected operator 正在删除 “diversion of /bin/sh to /bin/sh.distrib by dash”
# testing the for variable after the looping for test in Alabama Alaska Arizona Arkansas California Colorado do echo "The next state is $test" done echo "The last state we visited was $test" test=Connecticut echo "Wait, now we're visiting $test" ...
# 不具有可移植性的截获的文件foo-bar(){..;}# Undefined/unsupportedfunctionname # 未定义/不支持的函数名[$UID=0]# Variableundefinedindash/sh # dash/sh 中未定义的变量localvar=value # local isundefinedinsh # sh 中未定义localtime sleep1|sleep5# Undefined usesof'time'# 使用了time未定义的...
#!/bin/bash # using a global variable to pass a value function dbl { value=$[ $value * 2 ] } read -p "Enter a value: " value dbl echo "The new value is: $value" $value 变量在函数外定义并被赋值。当 dbl函数被调用时,该变量及其值在函数中都依然有 效。如果变量在函数内被赋予了新...
Forexample,sayyourscriptneedstoreportaninvalidargumentthatisstoredinthe BADPARM variable. You can print the diagnostic message with the following line so that the script name appears in the error message:0变量保存脚本的名称,对于生成诊断消息非常有用。例如,假设您的脚本需要报告存储在 BADPARM变量中的...