Bash make directory based on filename and add .itmsp
I need my script to wrap up files with specific extensions and XML into a directory that is named as per the files. In addition the directory needs to be renamed filename+.itmsp. At the moment the script creates a directory based on the filename but I am not sure how to add the .itmsp to the directory name.
#!/bin/bash
path='/Volumes/Drive/TEST'
cd $path
for FILE in开发者_如何学编程 `ls | egrep "xml|mov|mpeg|mpg"`
do
DIR=`echo $FILE | cut -d '.' -f 1`
mkdir -p $DIR
mv $FILE $DIR
done
Since this is bash:
cd /Volumes/Drive/TEST
for FILE in *.{xml,mov,mpeg,mpg}
do
# remove the last dot and subsequent chars, then add new ext
DIR="${FILE%.*}.itmsp"
mkdir -p "$DIR"
mv "$FILE" "$DIR"
done
Just append .itmsp to $DIR like "$DIR.itmsp".
精彩评论