grub2 的 if 指令
各位大神本人在https://ftp.gnu.org/gnu/grub/ 下載的grub-2.04-for-windows.zip
已製作了bootx64.efi 和 g2ldr 分別做成efi 和 mbr
但有個問題想請教各位大神
我的grub.cfg 其中一項
menuentry '正常啟動(Windows)' --unrestricted --hotkey="w" --class windows {
echo "platform = " $grub_platform
if [$grub_platform==pc] ; then
if search --file --set --no-floppy /bootmgr ; then
chainloader +1
elif search --file --set --no-floppy /ntldr ; then
chainloader +1
else
echo '沒有找到Windows'
sleep --verbose 5
fi
fi
if $grub_platform=="efi" ; then
if search --file --set --no-floppy /EFI/Microsoft/Boot/bootmgfw.efi ; then
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
else
echo '沒有找到Windows efi'
sleep --verbose 5
fi
fi
}
就是這裡 if [$grub_platform==pc] 無論如何改, 結果都為True
有改過if [$grub_platform=="pc"] / if ["$grub_platform"=="pc"] / if ["${grub_platform}"=="pc"]
還有這句 if search --file --set --no-floppy /bootmgr ; then, 也是一樣
我翻了好多文章, 結果還是一樣, 請問有解嗎? 我记得是
if [ "$grub_platform" = "pc" ] 江南一根葱 发表于 2020-7-12 15:10
我记得是
if [ "$grub_platform" = "pc" ]
這個也試過了, 還是不行
if [ "$grub_platform" = "pc" ] 和 if [ "$grub_platform" == "pc" ] 甚至 if [ "$grub_platform" != "pc" ]
結果都為True 2013ming028 发表于 2020-7-12 15:45
這個也試過了, 還是不行
if [ "$grub_platform" = "pc" ] 和 if [ "$grub_platform" == "pc" ] 甚至 if...
怎么试的,完整的 if空格[空格"$grub_platform"空格=空格"pc"空格] menuentry '正常啟動(Windows)' --unrestricted --hotkey="w" --class windows {
search --file --set=nt6 --no-floppy /bootmgr;
search --file --set=nt5 --no-floppy /ntldr;
search --file --set=efi --no-floppy /EFI/Microsoft/Boot/bootmgfw.efi;
if [ "$grub_platform" = "efi" ] -a [ -n "${efi}" ];
then
chainloader (${efi})/EFI/Microsoft/Boot/bootmgfw.efi
if [ "$grub_platform" = "pc" ] -a [ -n "${nt6}" ];
then
chainloader (${nt6})/bootmgr
fi;
if [ "$grub_platform" = "pc" ] -a [ -n "${nt5}" ];
then
chainloader (${nt5})/ntldr
fi;
else
echo '沒有找到Windows'
sleep --verbose 5
fi;
}
我瞎写的,没验证
wintoflash 发表于 2020-7-12 16:11
if空格[空格"$grub_platform"空格=空格"pc"空格]
以 : if空格[空格"$grub_platform"空格=空格"pc"空格] 方式寫
它出現 can't find command '[.
剛想到, 其實會不會 v2.4 版本的問題呢? 2013ming028 发表于 2020-7-12 16:58
以 : if空格[空格"$grub_platform"空格=空格"pc"空格] 方式寫
它出現 can't find command '[.
不是2.04的问题,是你的问题。
"[" 是 test 的别名,你没加test模块。 wintoflash 发表于 2020-7-12 17:56
不是2.04的问题,是你的问题。
"[" 是 test 的别名,你没加test模块。
謝謝大神
加上test 模块 果然能判斷了,
但還有另外一個問題, if search --file --set --no-floppy /bootmgr ; then 還是不能判斷, 還是為 Ture ??
页:
[1]