我正在学习 bash,现在想写一个刻录 iso 的脚本。我做了数字“4”命令来确保变量正确。
当我完成程序并执行 dd ie 时收到的消息command nr 5
./burn2.sh: line 39: /home/anon/dotsh/sudo dd if=/home/anon/Downloads/OS/Windows/Win10homepro/Win10.iso of=/dev/sdb1 bs=1M: No such file or directory
该脚本包含:
#!/bin/bash
#set -vx
speed=512K
iso_file="iso.txt"
dev_file="dev.txt"
speed_file="speed.txt"
while true
do
clear
echo "============================="
echo " Burning menu using dd "
echo "============================="
echo "Enter 1 for full path to iso."
echo "Enter 2 for media"
echo "Enter 3 to set bs speed 512K default"
echo "Enter 4 to save to files"
echo "Enter 5 to execute dd command"
echo "Enter q to exit q:"
echo -e "\n"
echo -e "Enter your choice \c"
read -r choice
case "$choice" in
q) exit ;;
1) echo -e "Enter path to iso \c"
read -r iso ;;
2) echo -e "Enter device"
read -r device ;;
3) echo -e "Enter bs speed \c"
read -r speed ;;
4) echo "$iso" > $iso_file
echo "$device" > $dev_file
echo "$speed" > $speed_file ;;
5) echo -e "Going to format $device, are you sure (y/N?) \c"
read -r $ans
if [[ "$ans" != "y" && "$ans" != "Y" ]]; then
echo "Clearing screen"
sleep 2
clear
exec "sudo dd if=$iso of=/dev/$device bs=$speed"
echo "Burning done!"
sleep 3
exit
fi
esac
done
答案1
exec "sudo dd if=$iso of=/dev/$device bs=$speed"
这将尝试用名为“...”的命令替换当前 shell(即整个字符串是姓名命令的)。该命令不存在,这就是为什么你会得到没有这样的文件或目录错误信息。
我不太明白为什么你想exec
在这里使用,特别是因为你在它之后还有进一步的命令要执行(exec
永远不会返回)。
相反,只需sudo
像平常一样调用:
sudo dd if="$iso" of="/dev/$device" bs="$speed"