📄 newext
字号:
#! /bin/bash## original from:# newext: change filename extension# @(#) newext.sh 1.1 93/04/13# 90/06/06 john h. dubois iii (john@armory.com)# 90/11/14 changed ksh-specific code to hybrid: if running under Bourne,# uses expr instead of ksh builtin ops. Removed SYSV specific code.# 91/08/06 added -t option# 92/11/06 made earlier code actually work!# 93/04/13 If no filenames given, act on files in current dir## conversion to bash v2 syntax by Chet Rameyusage="Usage: newext [-th] <oldext> <newext> [filename ...]"phelp(){echo "$usageRename all given files that end in oldext with newext replacing oldext.If no filenames are given, all files in the current directory that endin oldext are acted on (no filename is equivalent to '*').Options:-h: Print this help.-t: Test: No action is taken except to print the mv commands that wouldbe executed if -t was not given."}while getopts "th" opt; do case "$opt" in t) echo=echo;; h) phelp; exit 0;; *) echo "$usage" 1>&2; exit 2;; esacdoneshift $((OPTIND - 1))oldext=$1newext=$2case $# in [01]) echo -e "$usage\nUse -h for help." 1>&2; exit 2;;2) shift ; shift; set -- *;;*) shift ; shift;;esacfound=for filedo case "$file" in *$oldext) newname="${file%$oldext}$newext" $echo mv "$file" "$newname" found=true;; esacdoneif [ -z "$found" ]; then echo "No files ending in \"$oldext\"." exit 1fiexit 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -