cvt.sh
来自「Shall高级编程」· Shell 代码 · 共 40 行
SH
40 行
#!/bin/bash# cvt.sh:# Converts all the MacPaint image files in a directory to "pbm" format.# Uses the "macptopbm" binary from the "netpbm" package,#+ which is maintained by Brian Henderson (bryanh@giraffe-data.com).# Netpbm is a standard part of most Linux distros.OPERATION=macptopbmSUFFIX=pbm # New filename suffix. if [ -n "$1" ]then directory=$1 # If directory name given as a script argument...else directory=$PWD # Otherwise use current working directory.fi # Assumes all files in the target directory are MacPaint image files,#+ with a ".mac" filename suffix.for file in $directory/* # Filename globbing.do filename=${file%.*c} # Strip ".mac" suffix off filename #+ ('.*c' matches everything #+ between '.' and 'c', inclusive). $OPERATION $file > "$filename.$SUFFIX" # Redirect conversion to new filename. rm -f $file # Delete original files after converting. echo "$filename.$SUFFIX" # Log what is happening to stdout.doneexit 0# Exercise:# --------# As it stands, this script converts *all* the files in the current#+ working directory.# Modify it to work *only* on files with a ".mac" suffix.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?