Linux Shell的第一个小程序
2016-01-13 10:30
423 查看
#!/bin/bash # we have less than 3 arguments. Print the help text: if [ $# -lt 3 ]; then cat<<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' *.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
./ren 'txt$' 'txt1' *.txt
相关文章推荐
- bash编程之五 字符串测试以及for循环
- shell脚本编程之函数
- Shell中各种括号的用法
- xshell密钥登录
- Shell脚本文件中常用的操作语句
- Shell中一键添加作者,版权信息
- Linux 每日一练习:Login Shell 与Non-login Shell
- shell脚本一键安装MySQL5.5
- 第二章 Shell编程之变量
- shell脚本手动执行成功,定时任务调用失败的解决方法。
- shell中的括号(小括号,中括号,大括号/花括号)
- shells
- Bash定制化之ACCSI字符图
- 综合一句话Shell破解
- shell example01
- Bash定制化
- erlang的shell历史记录
- SSH Secure Shell Client 连接Linux 乱码
- Shell快捷键
- 查看服务器RAID卡信息的SHELL脚本及MegaCLI命令介绍