我正在尝试在 bash 脚本中使用大括号扩展,如下所示。
#!/bin/bash
document_root="/var/www/www.example.com"
`chmod -R g+w $document_root/{../captcha,../files}`
这给了我错误
chmod:无法访问`/var/www/www.example.com/{../captcha,../files}':没有这样的文件或目录
但是当我在终端中运行它时它工作得很好。
我正在尝试在 bash 脚本中使用大括号扩展,如下所示。
#!/bin/bash
document_root="/var/www/www.example.com"
`chmod -R g+w $document_root/{../captcha,../files}`
这给了我错误
chmod:无法访问`/var/www/www.example.com/{../captcha,../files}':没有这样的文件或目录
但是当我在终端中运行它时它工作得很好。
#!/bin/bash
document_root="/var/www/www.example.com"
chmod -R g+w $document_root/{../captcha,../files}
$
给变量时不要为变量添加前缀,仅在扩展时你试过这种方法吗?
#!/bin/bash
document_root="/var/www/www.example.com"
chmod -R g+w $document_root/{"../captcha","../files"}
我自己偶然发现了这个问题。就我而言set -eu
,我在脚本的某个位置使用命令导致了这个特定问题。修复是添加-B
选项,例如set -euB
重新启用大括号扩展,因为它已被禁用,尽管手动状态默认启用它。