. f_askdir.sh
. f_askstring.sh
ask_directory 1
if [ $? -eq 1 ]; then
return 1
fi
echo "Target directory is \"${_DIRNAME}\""
ask_string "Input Common Filename(Blank is 0mission): " 1
COMNAME=$_STR
if [ ! "$COMNAME" ]; then
echo "Omit Common Filename."
else
echo "Common Filename is \"${COMNAME}\""
fi
ask_string "Input Target Extension(Blank is Omission): " 1
EXTENSION=$_STR
if [ ! "$EXTENSION" ]; then
echo "Omit Extension."
else
echo "Extension is \"${EXTENSION}\""
fi
ask_string "Input prefix: " 0
PREFIX=$_STR
echo "Prefix is \"${PREFIX}\""
if [ ! "$COMNAME" -a ! "$EXTENSION" ]; then
SERCHNAME=*
elif [ "$COMNAME" -a ! "$EXTENSION" ]; then
SERCHNAME=$COMNAME*.*
elif [ ! "$COMNAME" -a "$EXTENSION" ]; then
SERCHNAME=*.$EXTENSION
else
SERCHNAME=$COMNAME*.$EXTENSION
fi
echo $SERCHNAME
CURRENDIR=$(pwd)
cd $_DIRNAME
NUM=0
for FNAME in $SERCHNAME; do
if [ -f "$FNAME" ]; then
mv $FNAME $PREFIX$FNAME
NUM=$(expr $NUM + 1)
fi
done
if [ $NUM -eq 0 ]; then
echo "No file."
else
echo "*** Successful."
fi
cd $CURRENTDIR
unset _DIRNAME COMNAME EXTENSION SERCHNAME CURRENTDIR FNAME NUM _STR
$ ls
b1.text b2.text b3.text b4.text b5.text
$ ./add_prefix.sh
Input Directory (Blank is Cancel.) : .
Target directory is "."
Input Common Filename(Blank is 0mission): b
Common Filename is "b"
Input Target Extension(Blank is Omission): text
Extension is "text"
Input prefix: a
Prefix is "a"
b1.text b2.text b3.text b4.text b5.text
*** Successful.
$ ls
ab1.text ab2.text ab3.text ab4.text ab5.text