how to extact value of variable from kernel commandline

I want to extract the value set to the root variable in following kernel command line, I don’t want to use awk column number.

console=ttyO0,115200n8 noinitrd mem=256M root=/dev/mmcblk0p2 rw rootfstype=ext4 rootwait=1 ip=none

I am able extract it using following command but it depends on the position of root variable but if that position changes it won’t work

cat /proc/cmdline | awk '{print $4}' | cut -d '=' -f2

Any suggestions/hint/pointers ?


Source: bash

Leave a Reply