在 bash 函数中使用 grep 和 cut

Use grep and cut inside a bash function

我有以下 bash 代码:

function () {
   curl="$(curl -s "" >> "")"
   version="$(grep ''  |  )"
   echo $version
}

function "test" "https://google.com" "String" "cut -d' ' -f3 | cut -d'<' -f1"

基本上,该函数会下载页面,然后使用 grep 查找特定字符串。在那之后 "cut",进一步减少结果。但是......不幸的是,函数内部的剪切不起作用。我只得到以下输出:

"usage: cut -b list [-n] [file ...]
       cut -c list [file ...]
       cut -f list [-s] [-d delim] [file ...]"

也许我忽略了一些东西......或者你有更好的主意:-)

由于</code>包含shell个元字符,展开变量时不处理,需要用<code>eval执行。

另外,</code>需要用双引号引起来,不能用单引号引起来,否则变量不会展开。</p> <pre><code> version="$(grep "" "" | eval "" )"