Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 在shell脚本中引用路径_Bash_Shell_Scripting_Quoting - Fatal编程技术网

Bash 在shell脚本中引用路径

Bash 在shell脚本中引用路径,bash,shell,scripting,quoting,Bash,Shell,Scripting,Quoting,我有一个shell脚本,它使用base64编码一个值并将其存储在一个变量中 encoded="$(cat $pathtofile|base64 -w 0)" 这一直有效,直到我得到一个$pathtofile,其中有一个特殊的角色。现在,我试图找出如何引用$pathtofile,以便cat获得正确的文件。当我这么做的时候 encoded="$(cat '$pathtofile'|base64 -w 0)" 我最终得到了一个错误,因为它没有展开$pathtofile,而是逐字打印。我尝试过其他几

我有一个shell脚本,它使用base64编码一个值并将其存储在一个变量中

encoded="$(cat $pathtofile|base64 -w 0)"
这一直有效,直到我得到一个$pathtofile,其中有一个特殊的角色。现在,我试图找出如何引用$pathtofile,以便cat获得正确的文件。当我这么做的时候

encoded="$(cat '$pathtofile'|base64 -w 0)"
我最终得到了一个错误,因为它没有展开$pathtofile,而是逐字打印。我尝试过其他几种组合,但它们都会导致错误引用路径


如何以引用的$pathtofile结束?

当您使用$..时,可以嵌套双引号

不管怎样,外部引号集是可选的。变量赋值中不需要它们。如果你愿意,就把它们拿走

encoded=$(cat "$pathtofile" | base64 -w 0)
另外,祝贺你,你赢得了一个冠军


使用$..时可以嵌套双引号

不管怎样,外部引号集是可选的。变量赋值中不需要它们。如果你愿意,就把它们拿走

encoded=$(cat "$pathtofile" | base64 -w 0)
另外,祝贺你,你赢得了一个冠军


感谢猫奖的无用使用;感谢猫奖的无用使用;可能的重复可能的重复
encoded=$(base64 -w 0 "$pathtofile")