Operating System - HP-UX
1822728 Members
3764 Online
109644 Solutions
New Discussion юеВ

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.


Bill Hassell
Honored Contributor

Re: which command error, need help

whence (and it's VERY useful alias type which is the even more useful whence -v) replaces which and whereis. Neither which nor whereis will tell you exactly what happens when you enter a string on the command line. which knows nothing about "for" but...

# which for
no for in /usr/sbin /usr/bin /opt/ansic/bin /usr/ccs/bin /usr/contrib/bin /opt/hparray/bin /opt/nettladm/bin /opt/upgrade/bin /opt/fcms/bin /opt/resmon/bin /opt/pd/bin /opt/gnome/bin /opt/perf/bin /opt/ignite/bin /usr/contrib...etc

# whereis for
for:

# whence -v for
for is a keyword.

which is useless for aliases and shell builtins. Other examples:

# type type
type is an exported alias for whence -v
# type ulimit
ulimit is a shell builtin.
# type pwd
pwd is a shell builtin.
# alias pwd=/usr/bin/pwd
# type pwd
pwd is an alias for /usr/bin/pwd

type (whence) tells you what will happen if you type a string of characters. It finds shell aliases, keywords, basically anything that the shell does for you. This is much more useful than which and whereis.

HP provides the scummy C shell but that doesn't mean you should use it. Fir sysadmins, only a real shell (with standards like POSIX) like ksh or the POSIX shell sh (or even bash) provide consistent and portable results.


Bill Hassell, sysadmin
Dennis Handly
Acclaimed Contributor

Re: which command error, need help

>I do have execute permission for which
-r-xr-xr-x 1 bin bin 664 Oct 4 18:04 /usr/bin/which

Do you have it for the scummy C shell?
ll /usr/bin/csh

While this is a rather clever trick to prevent users from using the scummy C shell, you should put the system back the way is was.

>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.

Not really, though similar:
$ which csh
/usr/bin/csh # scummy C shell
$ whence -pv csh
csh is /usr/bin/csh
$ whence -v csh
csh is a tracked alias for /usr/bin/csh

If you know what makes the C shell scummy, you would know that which(1) is scummy too.

And real shell users, use whence. Since it is built into a real shell, it can tell you more things.
Dennis Handly
Acclaimed Contributor

Re: which command error, need help

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

One other way to get this error is to link scummy csh to a real shell.
I get a different error if csh isn't executable.
sysad1_1
Advisor

Re: which command error, need help

thanks for all the replies. I already made use of whence instead of which.