+ -
当前位置:首页 → 问答吧 → ubuntu10.10 chmod 不能更改权限

ubuntu10.10 chmod 不能更改权限

时间:2011-02-25

来源:互联网

代码:
#!/bin/bash
declare -i n = 137
while [${n} < 160]
do
    convert ${n}.jpg -resize 100x100 /home/ubuntu/documents/J*/${n-136}.jpg
    n = n + 1
done

这是小弟写的第一个shell脚本,目的是想把当前目录下的137.jpg ,138.jpg ,139.jpg ,140.jpg ,141.jpg......159.jpg图片全部用convert的resize命令改成200x200大小,并分别重命名为1.jpg ,2.jpg......
但是目前出了一点错误,小弟刚学shell编程,出了什么笑话请包容一下 ,请高手麻烦改一下,小弟不知道哪里错了,顺便贴出错误,谢啦!
代码:
./shell.sh: 第 2 行: declare: “=”: 无效的标识符
./shell.sh: 第 2 行: declare: “137”: 无效的标识符
./shell.sh: line 3: 160]: 没有那个文件或目录

作者: NewUserFF   发布时间: 2011-02-25

NewUserFF 写道:
代码:
#!/bin/bash
declare -i n=137

变量定义“=”左右不能有空格

NewUserFF 写道:
代码:
while [ ${n} \< 160 ]

“<”比较操作符做算术比较时在“(( ))” 使用,在“[ ]”中使用“-lt”
另外“[ ]”前后最好有空格,推荐使用关键字“[[ ]]”
如果非要使用的话需要转义

最后由 sunfish 编辑于 2011-02-25 21:13,总共编辑了 5 次

作者: sunfish   发布时间: 2011-02-25

sunfish 写道:
NewUserFF 写道:
代码:
#!/bin/bash
declare -i n=137

变量定义“=”左右不能有空格

OK,把空格全部去掉了,现在代码是这样
引用:
#!/bin/bash
declare -i n=137
while [${n}<160]
do
convert ${n}.jpg -resize 100x100 /home/cityofsky/documents/J*/${n-136}.jpg
n=n+1
done

还是有问题
代码:
./shell.sh: line 3: 160]: 没有那个文件或目录

不过 160] 并不是一个文件或目录,这句话有什么错误吗?

作者: NewUserFF   发布时间: 2011-02-25

代码:
while [ ${n} -lt 160 ]

注意空格。

作者: ebok   发布时间: 2011-02-25

热门下载

更多