出于某种原因,在反引号和双引号内解析变量名会导致空新行。
search="randomsite";
res="`find /var/www -maxdepth 2 -mindepth 2 -type d -name '${search}'`";
echo $res
最佳答案
使用 $()
而不是反引号 - 它们更易于阅读和嵌套...
res=$(find /var/www -maxdepth 2 -mindepth 2 -type d -name "${search}")
关于linux - 为什么 find 在反引号内产生一个空的新行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22220241/