⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rn.sh

📁 BASH Shell 编程 经典教程 《高级SHELL脚本编程》中文版
💻 SH
字号:
#! /bin/bash## Very simpleminded filename "rename" utility (based on "lowercase.sh").##  The "ren" utility, by Vladimir Lanin (lanin@csd2.nyu.edu),#+ does a much better job of this.ARGS=2E_BADARGS=65ONE=1                     # For getting singular/plural right (see below).if [ $# -ne "$ARGS" ]then  echo "Usage: `basename $0` old-pattern new-pattern"  # As in "rn gif jpg", which renames all gif files in working directory to jpg.  exit $E_BADARGSfinumber=0                  # Keeps track of how many files actually renamed.for filename in *$1*      #Traverse all matching files in directory.do   if [ -f "$filename" ]  # If finds match...   then     fname=`basename $filename`            # Strip off path.     n=`echo $fname | sed -e "s/$1/$2/"`   # Substitute new for old in filename.     mv $fname $n                          # Rename.     let "number += 1"   fidone   if [ "$number" -eq "$ONE" ]                # For correct grammar.then echo "$number file renamed."else  echo "$number files renamed."fi exit 0# Exercises:# ---------# What type of files will this not work on?# How can this be fixed?##  Rewrite this script to process all the files in a directory#+ containing spaces in their names, and to rename them,#+ substituting an underscore for each space.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -