LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1245|回复: 2

怎么删除shell脚本中变量的部分值啊

[复制链接]
发表于 2003-4-8 17:18:03 | 显示全部楼层 |阅读模式
我想写一个删除部分文件名的脚本
可不知道怎么改变文件名为原来的一部分
比如把"123name"改为"name"
#!/bin/sh
cd "$1"
for file in *
do
   if [ -e $file ]; then
   newn=  //这里应该怎么写
   mv $file $newn
   fi
done
exit 0
发表于 2003-4-8 17:55:23 | 显示全部楼层
不知道这篇帖子对你是否有帮助,
http://www.linuxsir.cn/bbs/showthread.php?threadid=29282
发表于 2003-4-9 03:00:07 | 显示全部楼层
不知道这样是否可以?
1,建立如下文件:
$touch 123name 234the 345oki tmp temp newfile
$ls
123name  234the  345oki  newfile  temp  tmp
2,将所有以数字开头的文件的数字删除,即保留字母.
$file=$(ls|grep "^[0-9]..[a-z]")    <=变量中只包含有三个数字的文件
$for i in $file
>do
> mv $i ${i##[0-9][0-9][0-9]}
> done
$ls
name  newfile  oki  temp  the  tmp
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表