[問題] 遇到星號會亂掉,這啥鬼啊
這是我的 shell script
#!/bin/bash
routeStr2=$(route )
echo "================="
echo $(echo $routeStr2 | grep -c "default")
echo $routeStr2
exit 0
因為我想判斷route指令跑出來的東東有多少default指令, 迴圈就跑多少次...
問題來了
如果我把route執行結果直接dump string,
他會是一個字串,中間沒有斷行,
例如
routeStr2
Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use
Iface default 172.11.23.1 0.0.0.0 UG 0 0 0 eth0 default 192.168.42.129
0.0.0.0 UG 10 0 0 usb0 10.2.0.0 = download dwhelper examples.desktop font
fontconfig hs_err_pid27661.log hs_err_pid2938.log hs_err_pid2956.log img
index.html magic.mgc olv-0.log Perforce perforce.desktop proxy.pac test.sh
VirtualBox VMs workspace 公共 圖片 影片 文件 未命名文件 1 桌面 模板 音樂
255.255.0.0 U 1 0 0 eth1 140.112.172.0 192.168.42.129 255.255.255.0 UG 0 0 0
usb0 172.11.23.0 = download dwhelper examples.desktop font fontconfig
hs_err_pid27661.log hs_err_pid2938.log hs_err_pid2956.log img index.html
magic.mgc olv-0.log Perforce perforce.desktop proxy.pac test.sh VirtualBox
VMs workspace 公共 圖片 影片 文件 未命名文件 1 桌面 模板 音樂 255.255.254.0 U
1 0 0 eth0 192.168.42.0 = download dwhelper examples.desktop font fontconfig
hs_err_pid27661.log hs_err_pid2938.log hs_err_pid2956.log img index.html
magic.mgc olv-0.log Perforce perforce.desktop proxy.pac test.sh VirtualBox
VMs workspace 公共 圖片 影片 文件 未命名文件 1 桌面 模板 音樂 255.255.255.0 U
1 0 0 usb0
很亂吧, 只要routeStr2裡頭有星字號, bash會自動帶入當下目錄的內容
變成一沱怪東西
後來改為
#!/bin/bash
routeStr2=$(route )
echo "================="
echo $(echo "$routeStr2" | grep -c "default")
echo "$routeStr2"
星字號就不會被bash亂轉譯
請問這是為啥呢?
謝謝~
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 101.13.2.228
※ 文章網址: https://www.ptt.cc/bbs/Linux/M.1442198050.A.1B1.html
→
09/14 10:45, , 1F
09/14 10:45, 1F
所以glob pattern 就是.... 當下目錄的內容?
※ 編輯: pttnews (101.13.2.228), 09/14/2015 10:47:30
→
09/14 10:49, , 2F
09/14 10:49, 2F
→
09/14 10:49, , 3F
09/14 10:49, 3F
→
09/14 10:51, , 4F
09/14 10:51, 4F
→
09/14 10:52, , 5F
09/14 10:52, 5F
→
09/14 22:33, , 6F
09/14 22:33, 6F
→
09/15 09:54, , 7F
09/15 09:54, 7F
→
09/16 11:03, , 8F
09/16 11:03, 8F