Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I'm getting several odd shell script behaviors in BASH:
1) when I run a shell script, I get "command not found" errors for every line of the script -- but the script runs fine anyway. This is a simple script that sets some environment variables and then runs javac.
2) the first line #! /bin/sh causes the script to fail so I've taken it out. Same for #! /bin/bash. Both are there
3) The shell script can't read any environment variables. I have a one-line script that simply echos $MYVAR and here's what happens when I set MYVAR and then run the script:
> echo $MYVAR
the value of MYVAR is
Any advice here would be appreciated.
Last edited by HickorySlim; 07-26-2002 at 03:02 PM.
atleast for the third problem ,you should export <variable> ....when you execute a shell script it's
executed in a sub-shell with different environment from the one in which you are......what exactly do
you mean that #!/bin/bash causes script to fail.....can u post ur script here......
I see two likely possibilites for your "command not found" problem.
One, your path doesn't include the directory where these comands live,
or two, there is some typographical error at the top of your script which then prevents the rest of the script from being interpreted properly by bash. If the script is not too long, post it and someone may figure out the problem.
1) I don't have any space between #! and /bin/sh
2) semi-colons were I thought optional, but I removed them anyway to no avail
3) export $VARNAME is definitely not the way to go, as that only produces errors like "/usr/java/j2sdk1.4.0': not a valid identifier". Every time I've seen the export command used, it has been without the $.
One thing that's strange is I noticed when I do "which export" it shows no export in any of my bin directories! But last time I booted up it worked fine; previous to that it was broken again. Anyone ever heard of some "every other boot things are OK" problem??
when you are executing a script using ./<script-name> it is run inside a child shell with it's own
memory & environment.....so you cant export variables from that script to it's parent shell.....try something
as simple as
$ vi my_script
nothing will appear.....but . ./<script-name> will execute it in the current shell itself & hence no child
shell is created.....you can however put this line in ur .bashrc (or .profile whatever is executed in your
(Note the "dot" before scipt-path & this was meant on bash....I have never used ksh or csh)
This will set environmental variables at the same time when shell is created.....
& make a small correction in your script....
otherwise you are changing the path itself & that's why you got error on "which export" after executing
Hey, bingo! Executing in current shell works! So I guess `export` only exports to subshells, not parent shells?
Also, thanks for spotting the PATH problem. Strangely, though, even after a reboot and before running any scripts, I don't seem to have "export" on my system. I even did a full search:
find . -name 'export*'
from the root directory, and it doesn't seem to be on my system...
And finally, thanks for the no-semi-colon suggestion -- that solves the "command not found" mystery: it was apparently looking for a second command to execute on each line after the semi-colon, and of course it found none, but still nonetheless executed the command it did find before the semi-colon. It all makes sense now...
Thanks to everyone for your help! It's a good feeling having such a responsive community around you...
ADDENDUM: I started getting the old problems whenever I included that top #!/bin/sh line again... but this time one file worked while the other choked, in the same directory, same exact line on top. In addition, javac was behaving rather weirdly. I removed all but the top two lines, which were the #! line followed by an echo, and still one worked while other choked. I traced over each character, letter for letter with vi, and the two files were identical, except then I noticed in the corner that one file said "dos", and the character count was 2 chars longer. I ran dos2unix on all files and now they both work!
Last edited by HickorySlim; 08-02-2002 at 11:26 AM.
You won't find export because it's a bash builtin command. Go here and enter in the search box builtins and you'll get a list of the bash builtin commands. To find out more about the builtin commands, read bash's man page.
In place of the the dot " . " in front of the script name to get the script to execute in the current shell, you can use source. Ex.: