Linux编写Shell脚本获取指定目录下所有文件进行处理并保存到新目录
#!/bin/bash
app_name="shell"
path="/dir" #原目录
last_path="/newDir" #新目录
echo "======================start ${app_name}=============================="
if [ -n "$(ls $path)" ]; then
#echo "recordings is not empty"
cd $path
for file in *; do
if [ -f "$file" ]; then # 如果是文件
#echo "this is a file:$file"
extension="${file##*.}" # 获取文件名中最后一个点号之后的部分作为后缀
case $extension in #判断文件类型
txt)
mv $file $last_path
echo $file" is nfo";;
mp4)
filename=$(basename "$file" .mjr)
#echo "文件名(不包含后缀):$filename"
if [[ "${file}" == *video* ]]; then #视频
/usr/local/bin/pp-rec $file $last_path/$filename.mp4
echo $file" 文件名包含 video"
elif [[ "${file}" == *audio* ]]; then #语音
/usr/local/bin/pp-rec $file $last_path/$filename.mp3
echo $file" this is audio"
fi
rm $file
echo $file" is mp3";;
*)
echo $file" not file type";;
esac
elif [ -d "$file" ]; then # 如果是目录
echo "this is a dir:$file"
fi
done
else
echo "shell is empty"
fi
echo "======================end ${app_name}================================="
标签:Shell,last,Linux,echo,file,path,编写,filename,目录
From: https://www.cnblogs.com/eternality/p/17881796.html