0

我正在努力实现以下目标:

我有一个包含这一行的 config.php 文件:

define('URL', 'www.website.com');

在我的bash脚本中,我想在config.php中搜索,找到URL的值并将其存储到变量中。

知道怎么做吗?

4

2 回答 2

1

以下可能对您有用:

awk -F"[']" '/define/ && /URL/{print $4}' config.php

为了分配给一个变量,说:

var=$(awk -F"[']" '/define/ && /URL/{print $4}' config.php)
于 2013-10-16T07:52:31.447 回答
1

使用grep -P

grep -oP "^ *define *\( *'URL'[^']+'\K[^']+" config.php
www.website.com
于 2013-10-16T08:19:30.627 回答