1、第一个简单的for循环 #!/bin/bash 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而言没有
出现这种错误是因为有些linux系统默认会使用ash进行编译shell脚本,我的机器就是这样,但是我写的脚本是应该用bash执行的。虽然我在开头注明了#!/bin/bash,好像它还是默认去找了ash,真是让人无奈。上网搜索了一下,找到两种解决方案:1、修改脚本 2、修改系统默认执行shell的工具 第一种的具体做法就是,原来的for循环...
/bin/bash s=0 for (( i=1; i<=100; i++ )) do s=$(( $s + $i )) done echo $s 1. 2. 3. 4. 5. 6. 7. 8. 9. sh add.sh 报错: add.sh: 4: Syntax error: Bad for loop variable 代码没有错误,Ubuntu为了加快开机速度,用dash取代bash。 解决的方法:取消dash,使用bash: sudo...
发帖说明:http://www.fecshop.com/topic/624 如果是你自己的流水笔记,请到自己的博客里面发 hetao•#2•6年前 0 个赞 这个博客并不是我的,只是本着同样的问题别人也可能遇到另外修改脚本语法也是一种方案 hetao•#3•6年前 0 个赞 当然如果本论坛只接受bug报告,不接受fecshop有关的交流我不说什...
写shell脚本时碰到了这样的一个问题,脚本中一个循环语句采用了类C风格的for循环,结构如下 for ((i=1;i<=20;i++)) do ... ... done 但在本人ubuntu10.04的机器上运行此脚本会出现如下错误。 ./t.sh: 2: Syntax error: Bad for loop variable ...
# 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" ...
for var in ….; do …. done #!/bin/sh for var in A B C; do echo "var is $var" done 注:sh 不支持 C 语言风格的 for 循环写法,所以下面的脚本一定要把 shell 指定为 bash。参考:shell脚本:Syntax error: Bad for loop variable错误解决方法 #!/bin/bash for ((var=0;var<=3;var...
echo $1 # Unquoted variables #变量未加引号find.-name*.ogg # Unquoted find/grep patterns #find/grep 的匹配模式未加引号rm"~/my file.txt"# Quoted tilde expansion #引号中的波浪符扩展v='--verbose="true"';cmd $v # Literal quotesinvariables # 变量中的字面引号forfin"*.ogg"# Incorrectly quo...
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变量中的...
fish no longer searches directories from the Windows system/user $PATH environment variable for Linux executables. To execute Linux binaries by name (i.e. not with a relative or absolute path) from a Windows folder, make sure the /mnt/c/... path is explicitly added to $fish_user_paths ...