Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在努力实现以下目标:
我有一个包含这一行的 config.php 文件:
define('URL', 'www.website.com');
在我的bash脚本中,我想在config.php中搜索,找到URL的值并将其存储到变量中。
知道怎么做吗?
以下可能对您有用:
awk -F"[']" '/define/ && /URL/{print $4}' config.php
为了分配给一个变量,说:
var=$(awk -F"[']" '/define/ && /URL/{print $4}' config.php)
使用grep -P:
grep -P
grep -oP "^ *define *\( *'URL'[^']+'\K[^']+" config.php www.website.com