Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.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脚本中获取围绕参数的原始引号字符吗?_Bash_Arguments_Quotes - Fatal编程技术网

我可以在Bash脚本中获取围绕参数的原始引号字符吗?

我可以在Bash脚本中获取围绕参数的原始引号字符吗?,bash,arguments,quotes,Bash,Arguments,Quotes,我有一个记录用户参数列表的脚本。此列表稍后由getopt处理 如果脚本以如下方式启动: ./script.sh -a 'this is a sentence' -b 1 。。。然后我保存“$@”,我得到: -a this is a sentence -b 1 。。。没有单引号。我认为(因为Bash处理引号的方式),这些都被删除了,脚本无法使用 对于日志记录的准确性,我想包括报价了 是否可以在不引用引号的情况下获取原始参数列表?否,在shell对其执行空格标记化、通配符扩展和引号删除之前,无法

我有一个记录用户参数列表的脚本。此列表稍后由
getopt
处理

如果脚本以如下方式启动:

./script.sh -a 'this is a sentence' -b 1
。。。然后我保存
“$@”
,我得到:

-a this is a sentence -b 1
。。。没有单引号。我认为(因为Bash处理引号的方式),这些都被删除了,脚本无法使用

对于日志记录的准确性,我想包括报价了


是否可以在不引用引号的情况下获取原始参数列表?

否,在shell对其执行空格标记化、通配符扩展和引号删除之前,无法从中获取命令行

如果要传递文字引号,请尝试

./script.sh '"-a"' '"this is a sentence"' '"-b"' '"1"'
还要注意原始命令行是如何编写的

'./script.sh' '-a' 'this is a sentence' '-b' '1'

尝试:
“‘这是一个句子’
“\'这是一个句子\'
如果您想保持引号一致,我试图避免引用引号,因为这样做对最终用户有点不方便。:)