我的第二个“其他如果”不起作用。如果文件不存在,我无法下载文件。我不知道我在这里做错了什么。
#!/bin/bash
# upper case
file_upper_case=/root/MASTER.txt
# lower case
file_lower_case=/root/master.txt
if [ -e "$file_upper_case" ]; then
echo "File is upper-case"
echo "Changed to lower_case"
mv $file_upper_case $file_lower_case
chmod 664 $file_lower_case
chown root.dba $file_lower_case
else if [ -e "$file_lower_case" ]; then
echo "File is lower_case"
echo "Change permission only"
chmod 664 $file_lower_case
chmod root.dba $file_lower_case
else if [ -e "$file_lower_case"]; then
echo "File does not exist"
echo "Create master.txt file"
# Download master.txt file
wget --no-check-certificate https://github.com/userid/bin/raw/master.txt -P /root
chmod 664 /root/master.txt
chown root.dba /root/master.txt
fi; fi
答案 0 :(得分:4)
你可能想要这个(已测试):
#!/bin/bash
file_upper_case=/root/MASTER.txt
file_lower_case=/root/master.txt
if [ -e "$file_upper_case" ]; then
echo "File is upper-case"
echo "Changed to lower_case"
mv $file_upper_case $file_lower_case
chmod 664 $file_lower_case
chown root.dba $file_lower_case
elif [ -e "$file_lower_case" ]; then
echo "File is lower_case"
echo "Change permission only"
chmod 664 $file_lower_case
chmod root.dba $file_lower_case
else
echo "File does not exist"
echo "Create master.txt file"
# Download master.txt file
wget --no-check-certificate https://github.com/userid/bin/raw/master.txt -P /root
chmod 664 /root/master.txt
chown root.dba /root/master.txt
fi
答案 1 :(得分:0)
您可以使用elif
代替else if
。此外,你错过了最后一个条件中的空格。