Linux Shell的第一个小程序

来源:互联网 发布:我的淘宝p图 编辑:程序博客网 时间:2024/05/20 18:47
#!/bin/bash# we have less than 3 arguments. Print the help text:if [ $# -lt 3 ]; thencat<<HELP    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' *.HTMHELPexit 0fiOLD="$1"NEW="$2"# The shift command removes one argument from the list of# command line arguments.shiftshift# $* contains now all the files:for file in $*; doif [ -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"        fifidone

./ren 'txt$' 'txt1' *.txt
1 0
原创粉丝点击