Skip to content

Instantly share code, notes, and snippets.

@xie-qianyue
Created July 25, 2018 11:20
Show Gist options
  • Save xie-qianyue/83b77cd2f8de3fd4d47c13add13d1f9d to your computer and use it in GitHub Desktop.
Save xie-qianyue/83b77cd2f8de3fd4d47c13add13d1f9d to your computer and use it in GitHub Desktop.
rename the suffix
# common.lib
# Note no #!/bin/sh as this should not spawn
# an extra shell.
STD_MSG="About to rename some files..."
rename()
{
# expects to be called as: rename .txt .bak
FROM=$1
TO=$2
for i in *$FROM # = *.txt
do
j=`basename $i $FROM` # get the basename of the file
mv $i ${j}$TO # ${j}$TO = someBaseName.bak
done
}
#!/bin/sh
# function.sh
. ./common.lib
echo $STD_MSG
rename .txt .bak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment