字符串比较的问题

sh/bash/dash/ksh/zsh等Shell脚本
回复
yangstone
帖子: 28
注册时间: 2007-10-19 18:29

字符串比较的问题

#1

帖子 yangstone » 2010-01-02 14:51

我想写个脚本将某个文件夹下面出现的pdf文件全部移动到某个地点,、

for filename in $tempfile
do
if test -e .*pdf
then
mv filename ./doc/

tempfile 保存有当前文件夹下的文件列表,但是test哪一行有问题,字符串比较不对呀,望各位指教
头像
xiooli
帖子: 6956
注册时间: 2007-11-19 21:51
来自: 成都
联系:

Re: 字符串比较的问题

#2

帖子 xiooli » 2010-01-02 15:16

代码: 全选

find your_dir -name "*pdf" -exec mv {} another_dir \;
ps: 此命令系在 win 下敲滴,未经验证,请先验证无误后再使用,如出现任何问题,本人概不负责,特此声明!
yangstone
帖子: 28
注册时间: 2007-10-19 18:29

Re: 字符串比较的问题

#3

帖子 yangstone » 2010-01-02 15:30

明白你的意思,我还是想搞清楚为什么我写的那个字符串比较不对呢?

ps:因为下载的东西都在一个文件夹下,所以很乱,想写个脚本,用cron来做的,将文件归类以下,没写过脚本,望指教了
yangstone
帖子: 28
注册时间: 2007-10-19 18:29

Re: 字符串比较的问题

#4

帖子 yangstone » 2010-01-02 15:42

改成了:
for filename in $tempfile
do
if [ $filename == "*.pdf" ]
then
mv $filename ./doc
还是不对呀!
yangstone
帖子: 28
注册时间: 2007-10-19 18:29

Re: 字符串比较的问题

#5

帖子 yangstone » 2010-01-02 15:59

改成 if [[ $filename == *pdf ]]对了,。。。。。。。。。。。。。。。。 :em06 :em06 :em06
回复