cancel
Showing results for 
Search instead for 
Did you mean: 

which command error, need help

 
SOLVED
Go to solution
sysad1_1
Advisor

which command error, need help

My which command is failing recently because of this error:

prompt@localhost>which
which[7]: Syntax error at line 7 : `(' is not expected.

I don't why, but already looked into other HP-UX servers with working "which" commands but the script is just the same.

#! /usr/bin/csh
# @(#) $Revision: 72.1 $
#
# which : tells you which program you get
#
set noglob
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
if ( -e $arg ) then
echo $arg
else
echo $arg not found
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
endif
end


What seems to be the problem in here and how can i fix it? Thanks!


13 REPLIES 13
Mounaam
Trusted Contributor
Solution

Re: which command error, need help

it's as if your script is interpreted by a sh-like shell (sh, ksh...) instead of /usr/bin/csh.
Try this to confirm:
$ sh /usr/bin/which
$ csh /usr/bin/which

Can you check that your csh has not changed (or replaced by another thing).

What is the result of:
$ what /usr/bin/csh

Regards,
Mounaam
sysad1_1
Advisor

Re: which command error, need help

here are the command outputs you requested:

# sh /usr/bin/which
/usr/bin/which[7]: Syntax error at line 7 : `(' is not expected.
# csh /usr/bin/which
sh: csh: Execute permission denied.


# what /usr/bin/csh
/usr/bin/csh:


James R. Ferguson
Acclaimed Contributor

Re: which command error, need help

Hi:

> sh: csh: Execute permission denied.

It looks like you don't have execute permissions. This should look like:

# -r-xr-xr-x 1 bin bin 654 Feb 15 2007 /usr/bin/which

Regards!

...JRF...
Hakki Aydin Ucar
Honored Contributor

Re: which command error, need help

Check it like JRF said, it should look like;

# ls -l /usr/bin/which
-r-xr-xr-x 1 bin bin 654 Nov 14 2000 /usr/bin/which
Hakki Aydin Ucar
Honored Contributor

Re: which command error, need help

Hi,

And besides, you can check these also:
# file /usr/bin/which
/usr/bin/which: commands text
# what /usr/bin/which
/usr/bin/which:
B.11.11_LR
# echo $0
/sbin/sh
Dennis Handly
Acclaimed Contributor

Re: which command error, need help

>My which command is failing recently because of this error:

Any reason you are using the scummy C shell or one if its utilities?
The real shell has "whence".
Pete Randall
Outstanding Contributor

Re: which command error, need help

> Any reason you are using the scummy C shell or one if its utilities?

Check your's, Dennis. I think you'll find that that is the way HP provided it to us: with the scummy C shell!


Pete

Pete
Dennis Handly
Acclaimed Contributor

Re: which command error, need help

>Pete: I think you'll find that that is the way HP provided it to us: with the scummy C shell!

And that's why you don't use which(1).
sysad1_1
Advisor

Re: which command error, need help

Hi everyone,

i do have execute permission for which

>ls -l /usr/bin/which
-r-xr-xr-x 1 bin bin 664 Oct 4 18:04 /usr/bin/which

>csh /usr/bin/ls
sh: csh: Execute permission denied.

by the way, is the "whence" and "which" command just the same? in my 5 years of IT work experience I never knew that there was a "whence" command.