如果我解雇" zcat1" [它并不存在于所有平台上]并立即回应" $?",我在Linux和AIX中获得故障值[1]而不是在HP-UX中和Solaris? 请让我知道,遗漏的是什么,我到处都在使用sh shell?我需要进行任何设置吗?
uname -a
Linux xxxxx 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
[root@xxxxx tmp_a]# which zcat1
/usr/bin/which: no zcat1 in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/bin/admincmd/:/root/bin)
[root@cllin11 tmp_a]# echo $?
1
uname -a
AIX xxxxxx 1 7 00CE6F1F4C00
[root@xxxxx /]# which zcat1
which: 0652-141 There is no zcat1 in /usr/bin /etc /usr/sbin /usr/ucb /usr/bin/X11 /sbin /usr/java5/jre/bin /usr/java5/bin /root/bin /opt/VRTSvcs/bin /opt/VRTSvxfs/cfs/bin /etc/vx/bin /opt/pware/bin /opt/VRTSvcs/bin /etc/vx/bin /opt/VRTSvxfs/cfs/bin /opt/VRTS/bin /opt/pware/bin /opt/VRTSat/bin /opt/VRTSat/bin.
[root@claix01 /]# echo $?
1
# uname -a
HP-UX xxx B.11.23 U 9000/800 3547050632 unlimited-user license
# which zcat1
no zcat1 in /usr/sbin /usr/bin /usr/ccs/bin /usr/contrib/bin /usr/contrib/Q4/bin /opt/perl/bin /opt/ipf/bin /opt/hparray/bin /opt/nettladm/bin /opt/fcms/bin /opt/ssh/bin /opt/mx/bin /opt/wbem/bin /opt/wbem/sbin /opt/resmon/bin /usr/bin/X11 /opt/sec_mgmt/bastille/bin /opt/drd/bin /opt/dsau/bin /opt/dsau/sbin /opt/firefox /opt/gnome/bin /opt/perf/bin /opt/ignite/bin /usr/contrib/kwdb/bin /opt/mozilla /var/opt/netscape/servers/shared/bin /var/opt/netscape/servers/bin /var/opt/netscape/servers/bin/slapd/server /var/opt/netscape/server7/shared/bin /var/opt/netscape/server7/bin /opt/graphics/common/bin /opt/perl_32/bin /opt/perl_64/bin /opt/prm/bin /usr/sbin/diag/contrib /opt/sfm/bin /opt/sec_mgmt/spc/bin /opt/java1.4/jre/bin /opt/spb/bin /opt/swa/bin /opt/hpsmh/bin /opt/thunderbird /opt/upgrade/bin /opt/gwlm/bin /usr/contrib/bin/X11 /sbin /home/root
# echo $?
0
uname -a
SunOS xxxxxx 5.10 Generic_141445-09 i86pc i386 i86pc
# which zcat1
no zcat1 in /usr/sbin /usr/bin /opt/VRTS/bin /var/VRTS/bin/
# echo $?
0
答案 0 :(得分:2)
你正盯着POSIX实施地狱的深渊......这里有来自“红木城甲骨文”的小窍门,可以帮助你:
答案 1 :(得分:1)
好吧,hp-ux manpages for which
没有说退出状态,所以你不应该期待一个。
作为替代方案,您可以使用type
is part of POSIX,并且应该在失败时返回错误代码。
答案 2 :(得分:0)
其他答案已经涵盖了为什么你不能依赖which
的退出状态。在bash中,你应该使用内置type
,它不会因操作系统而改变。
$ type -P ls
/bin/ls
$ echo $?
0
$ type -P askdjas
$ echo $?
1