【发布时间】:2015-12-04 07:41:17
【问题描述】:
我是 shell 脚本的新手,我正在尝试使用 shell 脚本将文件“main.sh”备份到“main.sh.bak”。如果文件存在执行复制,否则显示一条消息。下面是我正在尝试的脚本,我需要在“if”条件下提供帮助以检查文件是否存在于当前目录中。
#!/bin/bash
echo "enter the file name"
read FILE
if [ -f $FILE ]; then
cp $FILE $FILE.bak
echo "file successfully backed up"
else
echo "file does not exists"
exit 1
fi
exit 0
【问题讨论】: