[CentOS] bash file direct execution

Mon Aug 1 17:48:27 UTC 2005
Matt Hyclak <hyclak at math.ohiou.edu>

On Mon, Aug 01, 2005 at 07:39:06PM +0200, dan1 enlightened us:
> >--- Johnny Hughes <mailing-lists at hughesjr.com> wrote:
> >
> >> On Sun, 2005-07-31 at 15:56 +0200, dan1 wrote:
> >> > Hi all.
> >> >
> >> > I have a little strange problem.
> >> > I created a file called 'test.sh' in the root directory containing:
> >> > #!/bin/sh
> >> > echo test
> >> >
> >> > When I execute it with '/test.sh' there is no output.
> >> > When I source it by executing it with '. /test.sh' the output comes ok.
> >> > When I move it to '/root' and execute it with '/root/test.sh' then it 
> >> > works
> >>
> >> > perfectly.
> >> > When I move it to '/home' and execute it with '/home/test.sh' there is 
> >> > no
> >> > output.
> >> >
> >> > Could someone tell me what I shoud do to make the script run without
> >> > sourcing it with '.' ?
> >> > This problem happens only on one CentOS 4 box I have, on the others it
> >> works
> >> > perfectly. What am I doing wrong ?
> >> > The permissions are 755 on the file itself, and I execute them logged 
> >> > as
> >> > root.
> >> >
> >> > Thanks,
> >> > Daniel
> >> >
> >>
> >> Dan,
> >>
> >> I can't duplicate your issue ... test.sh prints test on my xterm console
> >> every time.
> >>
> >> It works whether I use echo test or echo "test" ... and works with
> >> #!/bin/sh or #!/bin/bash ... on my CentOS-4 i386 machine.
> >>
> >> It also worked for both root and a non-root user.
> >>
> <> --
> >> Johnny Hughes
> >> > _______________________________________________
> >>
> >
> >Does this happen with all the scripts you try to run or just this one?
> >
> >If it is just with this one,  rename it to something like  abc.sh
> >and see if it works.
> >
> >Could be because the shell is getting it confused with the 'test' operator.
> >
> 
> Hello all.
> 
> Thanks for your try to help me, Johnny, Peter and Bruce.
> 
> Yes, this happens with almost all scripts. However I don't think that this 
> is related to the PATH, because I can even access the file directly with 
> it's path like '/test.sh' and the problem is the same.
> I also renamed the file and this doesn't change anything to the problem 
> neither.
> 
> 
> On one script that I have, it went differently:
> 
> [root at box scripts]# ./get_ipaddress
> bash: ./get_ipaddress: bin/sh: bad interpreter: No such file or directory
> [root at box scripts]# sh ./get_ipaddress
> 154.37.1.234
> [root at box scripts]#
> 
> This script is the following:
> 
> #!bin/sh
> CURRENT_IP=`/sbin/ifconfig eth0 | grep inet | cut -d : -f 2 | cut -d \  -f 
> 1`
> export CURRENT_IP
> echo $CURRENT_IP
> 

You need to change the first line to #!/bin/sh
                                       ^

Otherwise, the script is looking for a bin directory in whatever current
directory you are in. Unless you are at the root of the filesystem, it most
likely won't be found.

Matt

-- 
Matt Hyclak
Department of Mathematics 
Department of Social Work
Ohio University
(740) 593-1263
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.centos.org/pipermail/centos/attachments/20050801/933b711c/attachment-0004.sig>