Re: confounded by a simple shell script

Gordon Messmer <[email protected]>
Newsgroups gmane.linux.redhat.release.enigma
Message-ID <[email protected]>
Scott Queen wrote:
> Script (computeStats.sh) that doesn't work and it's output (Version 1):
> 
> # set environment variables
> ./home/dokimos_web/.bash_profile
> #  TC defined in .bash_profile file
> echo $TC   
> exit 0
> ----------------------------------
> results:
> 
> dokimos_web:logs>./computeStats.sh
> : No such file or directoryokimos_web/.bash_profile

There's a DOS carriage return character at the end of that line.  The 
error is:
./home/dokimos_web/.bash_profile\r: No such file or directory

When the CR character gets printed, the cursor returns to the beginning 
of the line (which is what CR does).  The last part of the line, then, 
overwrites a part of the beginning.

What you want, I'd imagine, is to do this, instead:
. /home/dokimos_web/.bash_profile

You'll also want to remove those DOS CR's.  It's really easy:
tr -d '\r' < file > new-file

You may also have dos2unix installed, which does the same thing:
dos2unix -o file


> '/computeStats.sh: exit: bad non-numeric arg `0

Probably also a DOS CR.

> =================================================
> Script (computeStats.sh) that doesn't work and it's output (Version 2):
> 
> #!/bin/bash
> # set environment variables
> ./home/dokimos_web/.bash_profile
> echo $TC
> exit 0
> ------------------------------
> results:
> dokimos_web:logs>./computeStats.sh
> bash: ./computeStats.sh: bad interpreter: No such file or directory

That's also a DOS CR.  The kernel is not trying to load /bin/bash, it's 
trying to load /bin/bash\r as the interpreter.

> So.... I have a couple of questions:
> 1.  why isn't the #!/bin/bash line required in the script that works?

sh is the default interpreter.

> 2.  why doesn't the other script work? [note that computeStats.sh has
> executable permissions for all users]

I suggest editing your scripts on Unix instead of DOS.  There are better 
editors, with syntax highlighting, everywhere you look.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.