[SOLVED] Bash command substitution, subshell & redirect
by Chuck56 from LinuxQuestions.org on (#5JA92)
I'm writing a bash script which needs the system bootloader type before taking additional actions. I'm focused primarily on LILO & EFI for Slackware systems but it should work for other bootloader types as listed in the table below.
I'm confused how the addition of a command substitution with a redirect to fd4 inside a subshell which is echoed inside another command substitution works?
How does the 80 in the 1st command convert to 5 in the 2nd command?
Code:bash-5.1$ cat /proc/sys/kernel/bootloader_type
80
bash-5.1$ echo $(($(cat /proc/sys/kernel/bootloader_type)>>4))
5Code: THE LINUX/x86 BOOT PROTOCOL
---------------------------
Assigned boot loader ids (hexadecimal):
0 LILO (0x00 reserved for pre-2.00 bootloader)
1 Loadlin
2 bootsect-loader (0x20, all other values reserved)
3 Syslinux
4 Etherboot/gPXE/iPXE
5 ELILO
7 GRUB
8 U-Boot
9 Xen
A Gujin
B Qemu
C Arcturus Networks uCbootloader
D kexec-tools
E Extended (see ext_loader_type)
F Special (0xFF = undefined)
10 Reserved
11 Minimal Linux Bootloader <http://sebastian-plotz.blogspot.de>
12 OVMF UEFI virtualization stack
Please contact <hpa@zytor.com> if you need a bootloader ID
value assigned.I found the original command on this page: https://unix.stackexchange.com/quest...ind-bootloader
Bash never ceases to amaze me with its never ending idiosyncrasies!


I'm confused how the addition of a command substitution with a redirect to fd4 inside a subshell which is echoed inside another command substitution works?
How does the 80 in the 1st command convert to 5 in the 2nd command?
Code:bash-5.1$ cat /proc/sys/kernel/bootloader_type
80
bash-5.1$ echo $(($(cat /proc/sys/kernel/bootloader_type)>>4))
5Code: THE LINUX/x86 BOOT PROTOCOL
---------------------------
Assigned boot loader ids (hexadecimal):
0 LILO (0x00 reserved for pre-2.00 bootloader)
1 Loadlin
2 bootsect-loader (0x20, all other values reserved)
3 Syslinux
4 Etherboot/gPXE/iPXE
5 ELILO
7 GRUB
8 U-Boot
9 Xen
A Gujin
B Qemu
C Arcturus Networks uCbootloader
D kexec-tools
E Extended (see ext_loader_type)
F Special (0xFF = undefined)
10 Reserved
11 Minimal Linux Bootloader <http://sebastian-plotz.blogspot.de>
12 OVMF UEFI virtualization stack
Please contact <hpa@zytor.com> if you need a bootloader ID
value assigned.I found the original command on this page: https://unix.stackexchange.com/quest...ind-bootloader
Bash never ceases to amaze me with its never ending idiosyncrasies!