LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell scripts running from /usr/local/bin - what did I forget to do? (https://www.linuxquestions.org/questions/linux-newbie-8/shell-scripts-running-from-usr-local-bin-what-did-i-forget-to-do-707799/)

steelangel 02-26-2009 02:23 PM

Shell scripts running from /usr/local/bin - what did I forget to do?
 
I haven't done shell scripting in a long while, and so I may have overlooked something. I need a second (or third or fourth) pair of eves.

I have written a shell script:
Code:

#!/bin/bash

latex $1.tex
dvips -t letter $1.dvi -o $1.ps
ps2pdf $1.ps $1.pdf
acroread $1.pdf

I have saved the shell script as the file /usr/local/bin/latexme. It is world-executable.
Code:

$ ls -aslt
...
8 -rwxr-xr-x 1 root root 94 Feb 26 10:38 /usr/local/bin/latexme
...

The directory /usr/local/bin is in my path.
Code:

$ echo $path
/usr/kerberos/bin /usr/local/bin /usr/bin /bin /usr/X11R6/bin

So, logically, I should see this when run from a directory:
Code:

$ latexme filename
(...latex/DVIPS/ output...)

Instead, I get:
Code:

$ latexme filename
latexme: Command not found.

However, this works:
Code:

$ /usr/local/bin/latexme filename
(...latex/DVIPS/ output...)

What obvious thing did I miss? For what it's worth, I'm using TCSH shell, and my distro is RHEL 5.

Tinkster 02-26-2009 02:32 PM

Ummm

What shell are you using?

$path isn't meaningful in any shell I've come across, and
$PATH should contain a colon-separated list of paths.



Cheers,
Tink

steelangel 02-26-2009 03:00 PM

I'm using tcsh:

Code:

$ chsh
Changing shell for <username>.
Password:
New shell [/bin/tcsh]: /bin/tcsh
Shell not changed.

$ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin

$ echo $path
/usr/kerberos/bin /usr/local/bin /usr/bin /bin /usr/X11R6/bin

You're right, $path should be $PATH, but that doesn't affect anything other than display.

Tinkster 02-26-2009 03:23 PM

Hmmm ... dunno; try using a sensible shell for a test. ;}

steelangel 02-26-2009 04:20 PM

No need to be snarky :P

It works under bash. Why it doesn't work in tcsh I don't know.

gergely89 02-26-2009 04:45 PM

Your script begins with '#!/bin/bash' but you are not using a BASH shell to launch the script. It seems that your shell (tcsh) passes the lower-case $path to the launched 'bash' instance, which within the bash realm yields an empty string. Could be that tcsh only maintains $path as an environment variable, and the $PATH output is rather a helpful hint from tcsh (clearly - I have no idea).

The fact that launching the script by full pathname works OK indicates that this is related to $path/$PATH in some way.

By replacing the slashbang to '#!/bin/sh' you might get different results, because 'sh' is usually a link to the default shell executable - on many system it defaults to bash, but that's not carved in stone.

linux

steelangel 02-27-2009 08:16 AM

I tried #!/bin/sh but that doesn't fit the issue; it still says that the command is not found.

On the $path vs. $PATH issue, I'm not exactly sure why it could be the source of the problem. Other executables run from the /usr/local/bin directory without the full path in the command line.

steelangel 02-27-2009 08:26 AM

And.. it's fixed.

Apparenly the thing I forgot to do is to rehash. After a logout and login unrelated to this script issue, it suddenly started to work.

colucix 02-27-2009 08:28 AM

Edit: didn't see your fix before posting. That's ok. Normal behaviour in tcsh.


All times are GMT -5. The time now is 02:42 PM.