使用命令行输出时获取语法错误
我正在尝试使用命令将输出存储在下面的脚本中,
#!/bin/bash
OUTPUT=${ls -al}
echo "$OUTPUT"
当我尝试执行时,
(localhost)$ ./subst.sh
./subst.sh: line 3: ${ls -al}: bad substitution
我会遇到以下语法错误:我在这里做错了什么?
I am trying to use command to store the output with the below script
#!/bin/bash
OUTPUT=${ls -al}
echo "$OUTPUT"
when I am trying to execute I am getting the below syntax error:
(localhost)$ ./subst.sh
./subst.sh: line 3: ${ls -al}: bad substitution
What is the wrong I am doing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要更改卷发括号并使用括号,因为
卷曲括号用于可变更改,并且用于命令替换,您需要在脚本中使用括号
You need to change the Curly braces and use Parenthesis because
Curly braces are used for variable change and for command substitution you need to use Parenthesis in your script as below