嘿,我有以下代码,它检查文件是否已经存在于它被删除之前最初的位置。
这工作,如果它不存在,那么它将被移动,这也是可行的,但我的问题是我如何获得shell脚本要求用户指定一个新名称重命名该文件,然后将其存储在新的名称如果已经存在同名的文件。 重命名的代码应该在if
的第一部分的echo中
#! /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 "please enter a new name: " newName mv /root/TAM/dustbin/$1 /root/TAM/dustbin/$newName cd /root/TAM rm store touch store
要提示用户,请尝试这样做:
read -p "New name >>> " name echo "The file name is $name"