在 Bash 中,可以对变量进行字符串操作,例如获取 Linux 机器上的当前运行级别:
current_runlevel=$(runlevel) #sample output: 'N 2'
current_runlevel=${current_runlevel#* }
echo $current_runlevel #sample output: '2'
但是,是否可以将这两行合并,因此不需要中间变量?使用相同的示例,我希望它看起来像:
current_runlevel=${$(runlevel)#* }
这不起作用,给出错误
${$(runlevel)#* }: bad substitution
关于如何在 Bash 字符串操作表达式中使用文字字符串的任何想法?