问一个有关与bash脚本的问题
Tofloor
poster avatar
daniel--di
deepin
2016-08-01 02:38
Author
自己写的,好像有问题,麻烦大神看一下,谢谢~目的是 i = 5 时输出
Reply Favorite View the author
All Replies
avatar
coslyk
deepin
2016-08-01 03:34
#1
  1. for i in {1..7}; do
  2.     if [ $i -eq 5 ]; then
  3.         echo ok
  4.     fi
  5. done
Copy the Code
Reply View the author
avatar
daniel--di
deepin
2016-08-01 03:38
#2

1.sh: 2: [: Illegal number: {1..7}
Reply View the author
avatar
coslyk
deepin
2016-08-01 03:45
#3
https://bbs.deepin.org/post/41942
1.sh: 2: [: Illegal number: {1..7}

for i in {1..7} 是比较新的语法,bash 3.0才有,你试下
  1. for ((i=1; i<=7; ++i)); do
  2.     if [ $i -eq 5 ]; then
  3.         echo ok
  4.     fi
  5. done
Copy the Code
Reply View the author
Comments
daniel--di
2016-08-01 04:34
解决了,但是需要把shell改为bash,方法:
错误为Syntax error: Bad for loop variable


解决办法:sudo dpkg-reconfigure dash
在选择项中选No

从 ubuntu 6.10 开始,ubuntu...
avatar
daniel--di
deepin
2016-08-01 04:34
#4
https://bbs.deepin.org/post/41942
for i in {1..7} 是比较新的语法,bash 3.0才有,你试下

解决了,但是需要把shell改为bash,方法:http://blog.sina.com.cn/s/blog_985bedb401015vrl.html
非常感谢
Reply View the author
avatar
coslyk
deepin
2016-08-01 07:17
#5
https://bbs.deepin.org/post/41942
解决了,但是需要把shell改为bash,方法:http://blog.sina.com.cn/s/blog_985bedb401015vrl.html
非常感 ...

其实开头带上 #!/bin/bash就好
Reply View the author
avatar
daniel--di
deepin
2016-08-01 08:14
#6
https://bbs.deepin.org/post/41942
其实开头带上 #!/bin/bash就好

hhh,好的,非常感谢
Reply View the author