如何从shell获取确切的命令行字符串? [英] How to get exact command line string from shell?
问题描述
我了解$*
,$@
,"$@"
甚至${1+"@"}
以及它们的含义.
I know about $*
, $@
, "$@"
and even ${1+"@"}
and what they mean.
我需要从shell脚本访问 EXACT 命令行参数字符串.请注意示例中的引号.像"$ @"之类的东西会保存参数,但会删除引号,但我不知道如何从中恢复.
I need to get access to the EXACT command-line arguments string from a shell script. Please pay attention to the quotes in the example. Anything like "$@" saves parameters but removes quotes and I don't see how to recover from this.
示例:
./my-shell.sh"1 2" 3
./my-shell.sh "1 2" 3
我需要检索 EXACT 参数字符串,而无需进行任何处理:
And I need to retrieve the EXACT parameter string without any processing:
"1 2" 3
"1 2" 3
有什么想法要实现吗?
推荐答案
在bash
中,您可以从shell历史记录中获得此信息:
In bash
, you can get this from the shell history:
set -o history
shopt -s expand_aliases
function myhack {
line=$(history 1)
line=${line#*[0-9] }
echo "You wrote: $line"
}
alias myhack='myhack #'
您所描述的作品:
$ myhack --args="stuff" * {1..10} $PATH
You wrote: myhack --args="stuff" * {1..10} $PATH
此外,这是一个方便的图表:
Also, here's a handy diagram:
这篇关于如何从shell获取确切的命令行字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!