找回密码
 注册
查看: 389|回复: 1

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

[复制链接]
发表于 2003-4-8 17:26:19 | 显示全部楼层 |阅读模式
我想写一个删除部分文件名的脚本
可不知道怎么改变文件名为原来的一部分
比如把"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 18:41:56 | 显示全部楼层
#!/bin/sh
cd "$1"
for file in *; do
if [ -f "$file" ]; then
newn= `echo "$file" | sed 's/123//g'`
mv $file $newn
fi
done
exit 0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2025-2-25 10:01 , Processed in 0.021685 second(s), 16 queries .

© 2001-2025 Discuz! Team. Powered by Discuz! X3.5.

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