shell 字符串连接

2025-05-10 07:12:08
推荐回答(3个)
回答1:

[root@zyh shell]# cat 判定文件名并改名.sh 
#!/bin/bash
#By Spinestars
read -p "Please input your file_path:" file_path
if [ -f $file_path ];then
mv $file_path $file_path"_"`date +%y%m%d`
echo $file_path"_"`date +%y%m%d`
else
echo "file_path is not found!"
fi
[root@zyh shell]# ./判定文件名并改名.sh 
Please input your file_path:/root/shell/1.file
/root/shell/1.file_130813


输入绝对路径

回答2:

你第一个 if 应该就是行的吧。只是你这文件名前后不一致啊, if 里的没有 .txt,mv 里的有 .txt。

回答3:

if [ -f speedlist.txt ];
then
mv speedlist.txt speedlit$(date +%Y%m%d%H%M%S)
fi

if [ -f avgspeed.txt ];
then
mv avgspeed.txt avgspeed$(date +%Y%m%d%H%M%S)
fi