我正在尝试将 ps 命令的输出输出到文件,然后使用该文件来填充无线电列表。到目前为止,我遇到了问题。
eval "ps -o pid,command">/tmp/process$$
more /tmp/process$$
sed -e '1d' /tmp/process$$ > /tmp/process2$$
while IFS= read -r pid command
do
msgboxlist="$msgboxlist" $($pid) $($command) "off"
done</tmp/process2$$
height=`wc -l "/tmp/process$$" | awk '{print $1}'`
width=`wc --max-line-length "/tmp/process$$" | awk '{print $1}'`
echo $height $width
dialog \
--title "Directory Listing" \
--radiolist "Select process to terminate" "$msgboxlist" $(($height+7)) $(($width+4))
到目前为止,while read 不仅没有将列拆分为 2 个变量($pid
是整行且$command
为空白),而且当我尝试运行此脚本时,脚本正尝试将该行作为命令运行。例如:
+ read -r pid command
++ 7934 bash -x assessment.ba
assessment.ba: line 322: 7934: command not found
+ msgboxlist=
+ off
assessment.ba: line 322: off: command not found
基本上我不知道应该在哪里放置引号、双引号和反斜杠。它让我疯狂。
tl; dr将命令保存到变量中而不运行它,如何?