gpt4 book ai didi

linux - 大括号扩展不起作用 bash

转载 作者:太空宇宙 更新时间:2023-11-04 09:07:09 25 4
gpt4 key购买 nike

我正尝试在 bash 脚本中使用大括号扩展,如下所示。

#!/bin/bash
document_root="/var/www/www.example.com"
`chmod -R g+w $document_root/{../captcha,../files}`

这给了我错误

chmod: cannot access `/var/www/www.example.com/{../captcha,../files}': No such file or directory

但是当我在终端中运行它时它工作得很好。

最佳答案

#!/bin/bash
document_root="/var/www/www.example.com"
chmod -R g+w $document_root/{../captcha,../files}
  1. 当您赋值给一个变量时,不要给变量加上前缀$,只有在展开时才
  2. 您不需要 chmod 周围的反引号,这样做会将整个事情视为一个命令

关于linux - 大括号扩展不起作用 bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8814445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com