SunOS 5.10 的“which”

SunOS 5.10 的“which”

我可以(普通用户)访问 SunOS 5.10 计算机。

/usr/bin/which已损坏(它会阻塞)。

显然系统出了问题,但没有 root 访问权限极大地限制了我能做的事情。我尝试which从 Ubuntu 复制,但这取决于 SunOS 5.10 上不可用的功能。

$ md5sum /usr/bin/which
a39bb82e9e354c5b99e9e235a53c48d9  /usr/bin/which
$ uname -a
SunOS solaris 5.10 Generic_147147-26 sun4u sparc SUNW,Sun-Fire-V210 Solaris
$ bash --version
GNU bash, version 4.3.33(1)-release (sparc-sun-solaris2.10)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

我在哪里可以找到which适用于这个旧系统的命令?

答案1

which命令在 Solaris 10 下不太可能被破坏。它只是一个csh脚本1

如果此脚本内容确实已损坏,您可以通过复制粘贴以下行来替换它。这将恢复其标准行为。

#! /usr/bin/csh -f
#
# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# Copyright (c) 1980 Regents of the University of California.
# All rights reserved.  The Berkeley Software License Agreement
# specifies the terms and conditions for redistribution.
#
#ident  "%Z%%M% %I% %E% SMI"
#
#       which : tells you which program you get
#
# Set prompt so .cshrc will think we're interactive and set aliases.
# Save and restore path to prevent .cshrc from messing it up.
set _which_saved_path_ = ( $path )
set prompt = ""
if ( -r ~/.cshrc && -f ~/.cshrc ) source ~/.cshrc
set path = ( $_which_saved_path_ )
unset prompt _which_saved_path_
set noglob
set exit_status = 0
foreach arg ( $argv )
    set alius = `alias $arg`
    switch ( $#alius )
        case 0 :
            breaksw
        case 1 :
            set arg = $alius[1]
            breaksw
        default :
            echo ${arg}: "      " aliased to $alius
            continue
    endsw
    unset found
    if ( "$arg:h" != "$arg:t" ) then        # head != tail, don't search
        if ( -e $arg ) then         # just do simple lookup
            echo $arg
        else
            echo $arg not found
        set exit_status = 1
        endif
        continue
    else
        foreach i ( $path )
            if ( -x $i/$arg && ! -d $i/$arg ) then
                echo $i/$arg
                set found
                break
            endif
        end
    endif
    if ( ! $?found ) then
        echo no $arg in $path
    set exit_status = 1
    endif
end

exit ${exit_status}

但是,挂起的一个更常见的原因which是 .txt 文件中列出的目录使用的文件系统之一存在问题PATH

这可能是 NFS 挂载无响应或本地文件系统出现问题。

这是开始调查的一种方法。运行此命令并查看它挂起的位置:

csh -x /bin/which foo

可能挂起的另一个原因which可能是您的文件存在问题,.cshrc因为它源自脚本的开头。

1 可能有人会说,由于它是一个csh脚本,which它就被设计破坏了;-)

答案2

我去了:

#!/bin/sh

type "$@" | perl -pe 's/.* is (a tracked alias for )?//'

这样它就可以作为 的直接替代品which

感谢@OlafDietsche 的评论。

相关内容