[問題] sed的一個問題
我手邊有一個Archlinux pacman安裝清單如下 :
----------------------------------------------------------------
#install.txt
atom #(see: C1. Configure Atom editor)
code #(see: C4. Configure vscode that like atom editor)
wget
p7zip
networkmanager
network-manager-applet #(attach to GUI setting)
gnome-nettool #(GUI network manager)
chromium
rsync
# (rsync is a good tool for backup on the local and the remote,
# It can implement copy and exclude some files or directories:
----------------------------------------------------------------
我要使用sed正規劃處理把#註解清除
查了一下sed的用法 寫個shell如下 :
----------------------------------------------------------------
#install.sh
pacman_cmd="pacman -S "
install_cmd=$(sed -e "s/#.*//" -e "s/^/${pacman_cmd}/" $1)
echo -e "\e[1;32m${install_cmd}\e[0m"
----------------------------------------------------------------
最後echo那段是顯示sed之後結果
執行的指令為 :
----------------------------------------------------------------
sh install.sh install.txt
----------------------------------------------------------------
期望的輸出如下 :
----------------------------------------------------------------
pacman -S atom
pacman -S code
pacman -S wget
pacman -S p7zip
pacman -S networkmanager
pacman -S network-manager-applet
pacman -S gnome-nettool
pacman -S chromium
pacman -S rsync
----------------------------------------------------------------
但實際的結果如下 :
----------------------------------------------------------------
pacman -S atom
pacman -S code
pacman -S wget
pacman -S p7zip
pacman -S networkmanager
pacman -S network-manager-applet
pacman -S gnome-nettool
pacman -S chromium
pacman -S rsync
pacman -S
pacman -S
----------------------------------------------------------------
多了2個空的pacman -S
我知道是最後兩行的#沒被消掉
但是sed應該有把它消掉呀QQ
其他都正確
到這邊就不會處理了orz
還請板上高手幫忙 謝謝!
--
我老婆-子瑜,不服出來灣阿
https://imgur.com/sCghzuF
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.246.112.102
※ 文章網址: https://www.ptt.cc/bbs/Linux/M.1540217296.A.0F1.html
推
10/22 22:22,
5年前
, 1F
10/22 22:22, 1F
→
10/22 22:34,
5年前
, 2F
10/22 22:34, 2F
→
10/22 22:34,
5年前
, 3F
10/22 22:34, 3F
推
10/22 22:35,
5年前
, 4F
10/22 22:35, 4F
→
10/22 22:37,
5年前
, 5F
10/22 22:37, 5F
請問
"s/^/${...}/"
這段是什麼意思
→
10/22 22:38,
5年前
, 6F
10/22 22:38, 6F
→
10/22 22:41,
5年前
, 7F
10/22 22:41, 7F
推
10/22 22:46,
5年前
, 8F
10/22 22:46, 8F
→
10/22 22:47,
5年前
, 9F
10/22 22:47, 9F
→
10/22 22:49,
5年前
, 10F
10/22 22:49, 10F
推
10/22 22:59,
5年前
, 11F
10/22 22:59, 11F
因為我會把它放在網頁
當作一種備忘錄
方便之後的安裝
順便學習正規化工具~~~
※ 編輯: dzwei (111.246.112.102), 10/22/2018 23:13:19
推
10/22 23:15,
5年前
, 12F
10/22 23:15, 12F
好 大致了解了 感謝您~~
※ 編輯: dzwei (111.246.112.102), 10/22/2018 23:23:52
已經更新上去我的筆記了
https://tinyurl.com/ycnkj395
這種一次安裝多個pacman package的方式在第六點
我也有附上參考連結在這篇文章
謝謝各位大大的幫忙
※ 編輯: dzwei (111.246.112.102), 10/23/2018 01:54:47