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))
지금까지뿐만 아니라 동안 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 명령을 실행하지 않고 변수에 저장하는 방법은 무엇입니까?
[하시기 바랍니다] (http://mywiki.wooledge.org/BashFAQ/048) [고려] (http://mywiki.wooledge.org/ProcessManagement) 당신이하고있는 일 (http : // www .grymoire.com/Unix/Quote.html). 그 코드는 무서워! [Code Review] (http://codereview.stackexchange.com/)에 게시하고 싶을 수도 있습니다. – l0b0