Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.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
Linux 带有args的bash别名在一个环境中工作,而不是在另一个环境中工作_Linux_Bash_Shell_Alias - Fatal编程技术网

Linux 带有args的bash别名在一个环境中工作,而不是在另一个环境中工作

Linux 带有args的bash别名在一个环境中工作,而不是在另一个环境中工作,linux,bash,shell,alias,Linux,Bash,Shell,Alias,我看到许多帖子指出shell别名不支持args。在CentOS 6.10和Bash 4.1.2这两个环境中,我有: alias hist='source ~/scripts/hist "@$"' (~/scripts/hist是一个shell脚本) 这很有效。脚本准确地从别名接收传递的参数。在另一个环境中—RHEL Server 7.5、Bash 4.2.46和类似的别名—唯一的区别是别名中的显式路径: alias hist='source /full/path/to/hist "@$"'

我看到许多帖子指出shell别名不支持args。在CentOS 6.10和Bash 4.1.2这两个环境中,我有:

alias hist='source ~/scripts/hist "@$"'
(~/scripts/hist是一个shell脚本) 这很有效。脚本准确地从别名接收传递的参数。在另一个环境中—RHEL Server 7.5、Bash 4.2.46和类似的别名—唯一的区别是别名中的显式路径:

alias hist='source /full/path/to/hist "@$"'
不起作用。当脚本运行时,它认为它收到了如下参数:“uid=nnnn(username)gid=nnnn(grpname)groups=nnnn(grp)”


这两个地方的脚本完全相同。我只是想知道可能的解释是什么。

它没有像预期的那样起作用,这里是一个最小的例子

alias print_args='printf "<%s>\n" "$@"'

print_args "hello" "world"
印刷品

<1>
<2>
<3>
<hello>
<world>
可能是“$@”,但可能不是预期的,在更好的情况下(未设置当前shell参数)是无用的,因为扩展为零,最坏的情况是设置了当前shell参数。请参见
echo“$@”
对不起,上面的输入错误-“$@”,而不是“@$”…您能做
echo“$@”吗
在shell的命令行中,它不工作,并与它工作的shell进行比较
set -- 1 2 3
print_args "hello" "world"
<1>
<2>
<3>
<hello>
<world>
alias print_args='printf "<%s>\n"'
print_args "hello" "world"