[分享]Shell编程基础
-
- 帖子: 46
- 注册时间: 2009-04-25 9:24
- _shendu
- 帖子: 147
- 注册时间: 2010-09-17 14:16
-
- 帖子: 14
- 注册时间: 2007-01-24 13:10
Re: [分享]Shell编程基础
嗯,好东西
-
- 帖子: 2
- 注册时间: 2010-10-24 11:00
Re: [分享]Shell编程基础
果断马克
- qq420100523
- 帖子: 1684
- 注册时间: 2009-07-31 18:56
- 系统: windows、ubuntu
- 来自: 广东阳江
Re: [分享]Shell编程基础
好文,这个要学习一下。。。
-
- 帖子: 1
- 注册时间: 2010-11-09 22:37
- icmmed
- 帖子: 46
- 注册时间: 2010-12-03 11:08
- zhoucga
- 帖子: 246
- 注册时间: 2009-06-12 8:55
-
- 帖子: 108
- 注册时间: 2010-12-18 19:46
Re: [分享]Shell编程基础
#!/bin/sh
# we have less than 3 arguments. Print the help text:
if [ $# -lt 3 ] ; then
cat < ren -- renames a number of files using sed regular expressions
USAGE: ren 'regexp' 'replacement' files...
EXAMPLE: rename all *.HTM files in *.html:
ren 'HTM$' 'html' *.HTM
HELP
exit 0
fi
OLD="$1"
NEW="$2"
# The shift command removes one argument from the list of
# command line arguments.
shift
shift
# $* contains now all the files:
for file in $*; do
if [ -f "$file" ] ; then
newfile=`echo "$file" | sed "s/${OLD}/${NEW}/g"`
if [ -f "$newfile" ]; then
echo "ERROR: $newfile exists already"
else
echo "renaming $file to $newfile ..."
mv "$file" "$newfile"
fi
fi
done
上面这段中的:
cat < ren -- renames a number of files using sed regular expressions
USAGE: ren 'regexp' 'replacement' files...
EXAMPLE: rename all *.HTM files in *.html:
ren 'HTM$' 'html' *.HTM
HELP
exit 0
是什么意思呀??能不能详细解释下!!谢谢了
# we have less than 3 arguments. Print the help text:
if [ $# -lt 3 ] ; then
cat < ren -- renames a number of files using sed regular expressions
USAGE: ren 'regexp' 'replacement' files...
EXAMPLE: rename all *.HTM files in *.html:
ren 'HTM$' 'html' *.HTM
HELP
exit 0
fi
OLD="$1"
NEW="$2"
# The shift command removes one argument from the list of
# command line arguments.
shift
shift
# $* contains now all the files:
for file in $*; do
if [ -f "$file" ] ; then
newfile=`echo "$file" | sed "s/${OLD}/${NEW}/g"`
if [ -f "$newfile" ]; then
echo "ERROR: $newfile exists already"
else
echo "renaming $file to $newfile ..."
mv "$file" "$newfile"
fi
fi
done
上面这段中的:
cat < ren -- renames a number of files using sed regular expressions
USAGE: ren 'regexp' 'replacement' files...
EXAMPLE: rename all *.HTM files in *.html:
ren 'HTM$' 'html' *.HTM
HELP
exit 0
是什么意思呀??能不能详细解释下!!谢谢了
keep the faith
-
- 帖子: 19
- 注册时间: 2011-01-03 20:25
Re: [分享]Shell编程基础
好东西啊
-
- 帖子: 26
- 注册时间: 2010-07-21 1:41
Re: [分享]Shell编程基础
支持一个
-
- 帖子: 3
- 注册时间: 2011-01-10 22:56
Re: [分享]Shell编程基础
顶这个啦。。值得学习的
-
- 帖子: 34
- 注册时间: 2011-01-03 16:18
- 联系:
-
- 帖子: 77
- 注册时间: 2008-12-31 17:45
Re: [分享]Shell编程基础
seb替换的那个例子还可以使用tr命令 tr "要替换的内容" "替换的内容" >>新文件
-
- 帖子: 77
- 注册时间: 2008-12-31 17:45
Re: [分享]Shell编程基础
好东西 收藏了 支持lz