Results 1 to 6 of 6
I am trying to write a bash script that sources another bash script. Essentially, I need a few lines to check to see if a certain variable is set. If ...
- 01-29-2011 #1Just Joined!
- Join Date
- Jan 2011
- Posts
- 3
Bash Script Help
I am trying to write a bash script that sources another bash script. Essentially, I need a few lines to check to see if a certain variable is set. If not, I set it manually, and then source a scripts with that variable in the path. I wrote a test script to try it, but for some reason the last line does not work. Here is what I wrote:
--------------------------------------------------------
#!/bin/sh
source ~setupdir/setup.shrc #just a test, this line works
echo ${#SETUP} # prints 0 if setup is not set, which it isn't
if [ ${#SETUP} -eq 0 ]
then
SETUP="~setupdir"
fi
echo $SETUP # prints ~setupdir
echo $SETUP/setup.shrc #prints ~setupdir/setup.shrc
source $SETUP/setup.shrc #this is the money line. It fails saying: "~setupdir/setup.shrc: No such file or directory"
-----------------------------------------------------------------------------------------
Can someone please help me. It seems to me that somehow the final line is not doing what I intend, since ~setupdir/setup.shrc exists and sourcing it on line 3 of the script is no problem.
ThanksLast edited by Ulrich82; 01-29-2011 at 04:31 PM.
- 01-29-2011 #2Why does one line refer to setup.sh and the other to setup.shrc?echo $SETUP/setup.sh #prints ~setupdir/setup.sh
source $SETUP/setup.sh #this is the money line. It fails saying: "~setupdir/setup.shrc: No such file or directory"
Is the variable $SETUP or is it SETUP/setup.sh?
or is there supposed to be yet another variable setup.sh?
- 01-29-2011 #3Just Joined!
- Join Date
- Jan 2011
- Posts
- 3
Sorry. It should all be .shrc. I'll edit it to fix.
I believe the answer to your question is that the variable is SETUP. It should point to the path to find setup.shrc.
Basically, I need to source the file setup.shrc to set up the libraries for the rest of my script. I am submitting this job to several computer farms. The farms should have the variable SETUP set to the correct path to find .shrc. So, I should be able to just call source $SETUP/setup.shrc in the first line of my code.
However, the computer farms are not standardized as they should be, and some of them do not have the variable SETUP set. So I need to check to see if SETUP is set, and, if it is not, I need to manually set SETUP to the correct path ~setupdir.
- 01-29-2011 #4remove the quotes around ~setupdirSETUP="~setupdir"
actually what I used was SETUP=~/setupdir
- 01-30-2011 #5Just Joined!
- Join Date
- Jan 2011
- Posts
- 3
Thanks. That seems to do it. I don't understand why the quotes caused a problem, but it is working now.
- 02-01-2011 #6
With the quotes, the shell doesn't interpret ~ and /
as path indicators but literally part of the file name.


Reply With Quote