關於正規表示 - Linux

Table of Contents

板友好

有一個檔案 tunnel_list 內容為

tunnel1
tunnel2
tunnel3


我寫了一個 script: remove_tunnel.sh 內容為

#!/bin/bash

sed -i 's/$1//g' tunnel_list
sed -i '/^$/d' tunnel_list



並在 shell 中丟入參數

./remove_tunnel.sh tunnel1


它無法刪除 tunnel1,因為$在sed中好像代表句尾,請問我參數1在 sed 中
要怎表示呢? 謝謝


--

All Comments

Irma avatarIrma2015-01-17
改成 sed -i "s/$1//g" tunnel_list 應該就可以了
Charlotte avatarCharlotte2015-01-20
謝謝。可以了..謝謝
Dorothy avatarDorothy2015-01-23
有 regexp 板喔~
Christine avatarChristine2015-01-27
這是跟linux相關的,因為shell不會expand單引號裡的變數
Hedy avatarHedy2015-01-31
嗯嗯 習慣性推廣,雖然我早已沒逛那板XD