0

我想将 find 命令的结果放到变量中 - 我在命令替换块中遇到变量问题。波纹管简短的例子:

#!/bin/bash

pattern='"file*"'
res=$(find . -maxdepth 1 -type f -name ${pattern}) # doesn't work
#res=$(find . -maxdepth 1 -type f -name "file*") # works
echo $res

怎么了?

4

1 回答 1

0

尝试

pattern="file*"
res=$( find . -maxdepth 1 -type f -name "${pattern}" )
于 2012-10-10T10:34:22.223 回答