English 中文(简体)
生产门槛值
原标题:Make Menu Entry efibootmgr Bash Linux
  • 时间:2024-02-24 09:09:26
  •  标签:
  • bash

我是双向的。

我已经在Batch和Powerhell发表《白奴》。 我想把它 in成黑白。

在bash,如果是某类信托,产出:

BootCurrent: 0003
Timeout: 2 seconds
BootOrder: 0011,0000,0001,0013,0014,0015,0004,0003,0016,0017
Boot0000* ThrottleStop UEFI
Boot0001* rEFInd Boot Manager
Boot0003* MX23 LinuX
Boot0004* Windows Boot Manager
etc...

我尝试:

#!/bin/bash

cd /home/mrkey7/Desktop/
sudo efibootmgr > file.txt
echo "$(grep "Boot00" file.txt)"
echo [R] Reboot
echo [S] Shutdown
echo [E] Exit

read -n 1 -p "Choose:" ans;
case $ans in
    r|R)
        sudo reboot;;
    s|S)
        sudo poweroff;;
    *)
        exit;;
esac

产出:

Boot0000* ThrottleStop UEFI
Boot0001* rEFInd Boot Manager
Boot0003* MX23 LinuX
Boot0004* Windows Boot Manager
[R] Reboot
[S] Shutdown
[E] Exit
Choose:

我希望产出如下:

[1] ThrottleStop UEFI
[2] rEFInd Boot Manager
[3] MX23 LinuX
[4] Windows Boot Manager
[R] Reboot
[S] Shutdown
[E] Exit
Choose:

然后,一只新闻“1”,就将boot到“ThrottleStop UEFI”。 供“rEFInd Boot”经理使用的“2”间。 等等。

页: 1 法典:

#!/bin/bash
sudo efibootmgr  | awk  /^Boot[0-9]/{ gsub(/[Bot*0]/, "", $1)
Index = ++ $1; sub(/^S+ /, "", $0)
printf("[% 2u] %s
", Index, $0); } 

echo [R] Reboot
echo [S] Shutdown
echo [E] Exit
read -n 1 -p "Choose:" ans;
case $ans in
    r|R)
        sudo reboot;;
    s|S)
        sudo poweroff;;
    *)
        exit;;
esac

the 产出:

[ 1] ThrottleStop UEFI
[ 2] rEFInd Boot Manager
[ 4] MX23 LinuX
[ 5] Windows Boot Manager
[ 2] Setup
[12] Boot Menu
[13] Diagnostic Splash
[14] USB FDD:
[15] ATA HDD: ADATA SU650
[16] USB HDD:
[17] USB CD:
[18] PCI LAN:
[R] Reboot
[S] Shutdown
[E] Exit
Choose:

new problem, new ask (maybe my first question wrong). I don t want number greater than 9. So, i want to replace the output number with Alphabet sequance ABCDE like this:

[A] ThrottleStop UEFI
[B] rEFInd Boot Manager
[C] MX23 LinuX
[D] Windows Boot Manager
[E] Setup
etc...
[1] Reboot
[2] Shutdown
[3] Exit
Choose:

问题回答

Here s a suggestion:

#! /bin/bash

set -o nounset

Letters=( {A..Z} )
Count=0

sudo efibootmgr        
| grep -e  ^Boot[0-9]  
| while read -r _ Line
  do    printf  [%s] %s
  "${Letters[Count ++]}" "$Line"
  done

echo  [1] Reboot 
echo  [2] Shutdown 
echo  [3] Exit 

文字使用宽度扩大,以产生一系列上层字母。

${Letters[0]} ————“A”—————————————————— --->“B”等

然后通过<条码>grep对输出进行过滤,并从“Boot{data}. 至<条码>。

<代码>read -r_ Line 构造将把每条线的第一字储存在离散变量“_”,并将其余部分储存到“Line”(“Boot0000* ThrottleStop UEFI,“$_”为“Boot0000*”,“$Line”为“ThrottleStop UEFI”。

在<代码>f第1条论点中,该次说明(Letters [.)被评为算术表述,便于使用工作地点差价调整数后操作员。

铭记您的EFI菜单应当包含27个条目。

Hope that helps.

页: 1

#!/bin/bash

set -o nounset
Count=0
Letters=( {A..Z} )
#Exclude: "Windows|FDD|PCI|CD|Splash"
sudo efibootmgr        
| egrep -v "Windows|FDD|PCI|CD|Splash" 
| grep -e  ^Boot[0-9]  
| while read -r _ Line
  do printf "[%s] %s
" "${Letters[Count ++]}" "$Line"
  done
echo  [1] Reboot 
echo  [2] Shutdown 
echo  [3] Exit 

read -n 1 -p "Choose:" ans;
case $ans in
    a|b|c|d|e) sudo efibootmgr -n xxxx; sudo reboot;;
    1) sudo reboot;;
    2) sudo poweroff;;
    *) exit;;
esac

产出:

[A] ThrottleStop UEFI
[B] rEFInd Boot Manager
[C] MX23 LinuX
[D] Setup
[E] Boot Menu
[F] ATA HDD: ADATA SU650
[G] USB HDD:
[1] Reboot
[2] Shutdown
[3] Exit
Choose:

下面的问题:

大约“|”

  • How to simplify code "a|b|c|d|e)" equivalent all "$Letters[...]" output ?.
  • Pass/ get "xxxx" value in "sudo efibootmgr -n xxxx" equivalent $ans ?.

我指的是,当新闻A 时,xx是“ThrottleStop UEFI”ID。 Press C , “MX23 LinuX” ID. Etc





相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签