Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux shell重命名文件(如果存在)_Linux_Shell - Fatal编程技术网

Linux shell重命名文件(如果存在)

Linux shell重命名文件(如果存在),linux,shell,Linux,Shell,嘿,我有下面的代码来检查文件在被删除之前是否已经存在于它原来所在的位置。 这是可行的,如果它不存在,那么它将被移动,这也是可行的, 但我的问题是,如果已经存在同名文件,如何让shell脚本要求用户指定一个新名称来重命名文件,然后将其存储在新名称下。 重命名代码应位于if #! /bin/sh #restore the dustbin contents if [[ -f "$(grep $1 /root/TAM/store) " ]]; then echo "A File with th

嘿,我有下面的代码来检查文件在被删除之前是否已经存在于它原来所在的位置。
这是可行的,如果它不存在,那么它将被移动,这也是可行的, 但我的问题是,如果已经存在同名文件,如何让shell脚本要求用户指定一个新名称来重命名文件,然后将其存储在新名称下。 重命名代码应位于
if

#! /bin/sh
#restore the dustbin contents 

if [[ -f "$(grep $1 /root/TAM/store) " ]]; then
   echo "A File with the same name already exists please rename this file to store it"
else 
   mv /root/TAM/dustbin/$1 `grep $1 /root/TAM/store`
   cd /root/TAM
   rm store
   touch store
fi
编辑


要提示用户,请尝试执行以下操作:

read -p "New name >>> " name
echo "The file name is $name"

@我将此代码
改为-p“请输入新名称”newName
然后
读$newName
mv/root/TAM/dustbin/$1$newName
但是这不起作用,为什么?你能看看我上面的新编辑,给我一些关于如何将文件移动到目的地的提示吗
grep$1/root/TAM/store
至于我的生活,我就是想不出怎么做我试过mv那样的版本这个
mv/root/TAM/dustbin/$newName
grep$1/root/TAM/store,但我确信它不起作用
mv/root/TAM/dustbin/$newName`grep$1/root/TAM/store`
。请注意grep表达式周围的`符号。您的脚本似乎已损坏。最好用英语告诉我们你真正想做什么,你的目标是什么&背景也许我忘记了墓穴钥匙,我会再试一次
read -p "New name >>> " name
echo "The file name is $name"