看板 Linux 關於我們 聯絡資訊
我寫了一支 shellscript,叫做 test.sh,內容是: #!/bin/bash var=$(ps aux | grep 'test' ) echo $var 然後我執行的時候輸入 ./test.sh 結果輸出: linux 7264 0.0 0.2 5180 1092 pts/0 S+ 22:33 0:00 /bin/bash ./test.sh linux 7265 0.0 0.1 5180 512 pts/0 S+ 22:33 0:00 /bin/bash ./test.sh linux 7267 0.0 0.1 4384 800 pts/0 S+ 22:33 0:00 grep test 如果把 shellscript 改成: #!/bin/bash ps aux | grep 'test' 會輸出: linux 7271 0.0 0.2 5176 1096 pts/0 S+ 22:36 0:00 /bin/bash ./test.sh linux 7273 0.0 0.1 4384 800 pts/0 S+ 22:36 0:00 grep test 想請問為何有這樣的差異呢 ? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.127.58.99 ※ 文章網址: https://www.ptt.cc/bbs/Linux/M.1432218987.A.0AF.html
kdjf: pross substitution是用sub shell實現的,多一層sh 05/21 23:06
goldie: 這兩個結果是不是放反啦?應該有echo的才會失去換行字元 05/22 13:08
pizzahut: 數目?那要加 | wc -l 啊 05/25 00:45