[英]How to give the output of a command as a reference to a variable in bash shell
I am creating a bash file.sh which will locate the path of a file and store the output of that command to use it later in another command.我正在创建一个 bash file.sh,它将定位文件的路径并存储该命令的 output 以便稍后在另一个命令中使用它。 This is what I've done so far:
这是我到目前为止所做的:
path_exe=${1:-locate binarycreator}
$path_exe -c config/config.xml -p packages $Name
when I'm running it I'm getting this: "locate: invalid option -- 'p'" Can anyone help me on this please?当我运行它时,我得到这个:“定位:无效选项 - 'p'”有人可以帮助我吗?
You have to store the first variable as a command.您必须将第一个变量存储为命令。 See below example which highlights what you are doing and how it is to be done.
请参阅下面的示例,该示例突出显示了您正在做什么以及如何完成。
bash-5.0$ a=${1:-'which ls'}
bash-5.0$ echo $a
which ls
bash-5.0$ $a
/usr/bin/ls # Notice only the command is printed but not executed.
---------------------------------------------
bash-5.0$ a=$(which ls)
bash-5.0$ echo $a
/usr/bin/ls
bash-5.0$ $a
aliases bin
# This executed the command
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.