我有一個phppgadmin
配置文件(/usr/share/phppgadmin/conf/config.inc.php
)修改配置線 它有一個線:如何使用shell腳本
$conf['extra_login_security'] = false;
我想將它更改爲:
$conf['extra_login_security'] = true;
使用bash
shell腳本。我知道我必須使用像sed/awk這樣的東西。但不知道如何使用它來做我想要的。
我有一個phppgadmin
配置文件(/usr/share/phppgadmin/conf/config.inc.php
)修改配置線 它有一個線:如何使用shell腳本
$conf['extra_login_security'] = false;
我想將它更改爲:
$conf['extra_login_security'] = true;
使用bash
shell腳本。我知道我必須使用像sed/awk這樣的東西。但不知道如何使用它來做我想要的。
如果你想要一個簡單的全局替換爲真,那麼sed 's/false/true/g'
將做到這一點。
$ echo "conf['extra_login_security'] = false" | sed 's/false/true/g'
conf['extra_login_security'] = true
但只改變行開始用conf[
和公正的值更改爲真,那麼這是更好的sed 's/\(^.*conf\[.*\] =\) false/\1 true/g'
echo "conf['extra_login_security'] = false" | sed 's/\(^.*conf\[.*\] =\) false/\1 true/g'
conf['extra_login_security'] = true
編輯:
只是該行可以用做如下:
sed -i 's/\(^.*conf\[.extra_login_security.\] =\) false/\1 true/' /usr/share/phppgadmin/conf/config.inc.php
使用-i
可以將更改保存到文件中,或者如果您不想覆蓋原始文件,則重定向到新文件。
sed 's/\(^.*conf\[.extra_login_security.\] =\) false/\1 true/' > mynewfile.php
,如果你沒有權限寫mynewfile.php
一個訣竅是管道輸出到tee
和sudo
是:
sed 's/\(^.*conf\[.extra_login_security.\] =\) false/\1 true/' | sudo tee mynewfile.php
從man tee
三通 - 從標準輸入和讀取寫入標準輸出和文件。