Bash无法识别变量赋值

时间:2015-03-15 17:22:45

标签: bash scripting

我在编写脚本时遇到问题。

clear
echo "Welcome to the dd interface"
echo "NOTE: When this program executes you will have to provide root access"
echo " "
lsblk

echo " "
read -p "Enter the location of the disk to be imaged: " input_location
echo "Input Location Assigned"

echo " "
read -p "Enter the output location: " output_location
echo "Output Location Assigned"

echo "
1 - 512K
2 - 1024K
3 - 2048K
4 - 4096K
"

blocksize = 0

read -p "Select the write block size to be used: " selection
echo "Block write size selected"


#problem is here
if [[ $selection == 1 ]]; then
        blocksize = 512
elif [[ $selection == 2 ]]; then
        blocksize = 1024
elif [[ $selection == 3 ]]; then
        blocksize = 2048
elif [[ $selection == 4 ]]; then
        blocksize = 4096
fi
echo "Options selected:
Input location: $input_location
Output location: $output_location
Block size: $blocksize
"

Bash将IF语句中的块大小视为命令而不是变量。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

你不应该在=处设置空格:

blocksize=0

而不是

blocksize = 0

应该有用。