Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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
Shell AIX上的ksh是否违反了POSIX.1-2004和POSIX.1-2008?_Shell_Posix_Aix - Fatal编程技术网

Shell AIX上的ksh是否违反了POSIX.1-2004和POSIX.1-2008?

Shell AIX上的ksh是否违反了POSIX.1-2004和POSIX.1-2008?,shell,posix,aix,Shell,Posix,Aix,我将以下shell脚本保存在一个名为foo.sh的文件中 username=$1 if [ -n "$username" ] then echo username: "$username" fi 我正在AIX5.3机器上运行此脚本 $ echo $SHELL /usr/bin/ksh $ sh foo.sh humpty username: humpty $ sh foo.sh = foo.sh[2]: test: 0403-004 Specify a parameter with t

我将以下shell脚本保存在一个名为foo.sh的文件中

username=$1
if [ -n "$username" ]
then
    echo username: "$username"
fi
我正在AIX5.3机器上运行此脚本

$ echo $SHELL
/usr/bin/ksh
$ sh foo.sh humpty
username: humpty
$ sh foo.sh =
foo.sh[2]: test: 0403-004 Specify a parameter with this command.
$ ksh foo.sh =
foo.sh[2]: test: 0403-004 Specify a parameter with this command.
$ ksh93 foo.sh =
username: =
$ bash foo.sh =
username: =
如果你想知道版本

$ ksh93 -c 'echo ${.sh.version}'
Version M-12/28/93e
$ bash --version
GNU bash, version 3.2.16(1)-release (powerpc-ibm-aix5.2.0.0)
Copyright (C) 2005 Free Software Foundation, Inc
我找不到确定ksh版本的方法

如您所见,当我将=指定为输入时,脚本会导致ksh出错。我可以在AIX5.3上用ksh重现这个错误,但在AIX5.3上不能用bash或ksh93重现这个错误。也许,当AIX上的ksh看到[-n=]时,它希望它是对两个相同字符串的测试

ksh的行为是否违反了POSIX.1-2004和POSIX.1-2008?会议上的文件明确指出了这一点

确定算子优先顺序的算法及其应用 应生成的返回值基于 提交给测试的参数。但是,在使用[…]形式时, 右括号内的最终参数不应计入本表 算法

在下面的列表中,$1、$2、$3和$4表示参数 提交测试:

0个参数: 退出false 1

1论点: 如果$1不为空,则退出true 0;否则,退出false

2个论点:

如果$1是“!”,如果$2为空,则退出true;如果$2不为空,则退出false

如果$1是一元主项,如果一元测试为真,则退出真,否则退出假 如果一元检验为假

否则,将生成未指定的结果


在本例中,[-n=]确实有2个参数,第一个参数确实是一元主参数,因此它应该测试=是否为非零字符串并退出true,而不是抛出错误。

shell是什么/bin/sh?我同意您的解释/Solaris 8和Solaris 10上的bin/sh同样易受攻击:用户名==;测试-n$username&&echo确定-测试:应为参数。Solaris 10/usr/xpg4/bin/sh echosok@EtanReisner“我想这是可敬的伯恩·谢尔。”格伦尼查克曼是我的假设。我主要是想澄清当前shell和/bin/sh之间的区别,但最近的编辑修复是相同的。@EtanReisner/bin/sh和/bin/ksh。它们具有相同的inode编号。