bash - 省略if语句

时间:2016-01-13 01:59:55

标签: bash if-statement

我很抱歉可能有一些微不足道的问题,但我两天前开始学习Bash。我还是新手:)。

if [ ! -d $backup_directory ]; then
        echo $'Backup device is not mounted or is mounted somewhere elese\a!'
        echo "Press enter when sdc device mounted to /mnt/sdc1 or past alternative path:"
        while [ ! -e $backup_directory ]; do
                alter_dev_path="" 
                read $alter_dev_path
                if [ "$alter_dev_path" != "" ]; then
                        $backup_directory=$alter_dev_path
                        $destination_directory=$alter_dev_path+"/sh-backup"
                        $result_path=$destination_directory+"/programming-base"
                fi
        done
fi

这就是来自我的备份脚本的if语句。我希望程序问我设备挂载目录。但是while循环只是省略if语句内部没有效果。 谢谢,Siery。

1 个答案:

答案 0 :(得分:2)

读取值:

read $alter_dev_path  # Wrong
read alter_dev_path   # Correct

分配值:

$destination_directory=$alter_dev_path+"/sh-backup"  # Wrong
destination_directory="$alter_dev_path/sh-backup"    # Correct
相关问题