[Solved] Variable defined in .bashrc not intializing in script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [Solved] Variable defined in .bashrc not intializing in script
# 1  
Old 02-12-2014
[Solved] Variable defined in .bashrc not intializing in script

I have the variable defined in .bashrc

BIN_DIR="/usr/local/dw"

and in my shell script i am using below.

Code:
#!/bin/bash
echo "Bin Dir: ${BIN_DIR}"
. "${BIN_DIR}"/dwh_Loadfuncs.sh

Output:
Code:
Bin Dir:
/usr/local/dw/dwh_LoadXMLFileIntoStage.sh: line 7: /dwh_Loadfuncs.sh: No such file or directory
/dwh_Loadfuncs.sh

May i please know why variable $BIN_DIR is not initialized?

Thank you.

---------- Post updated at 02:22 PM ---------- Previous update was at 02:20 PM ----------

Quote:
Originally Posted by Ariean
I have the variable defined in .bashrc

BIN_DIR="/usr/local/dw"

and in my shell script i am using below.

Code:
#!/bin/bash
echo "Bin Dir: ${BIN_DIR}"
. "${BIN_DIR}"/dwh_Loadfuncs.sh

Output:
Code:
Bin Dir:
/usr/local/dw/dwh_LoadXMLFileIntoStage.sh: line 7: /dwh_Loadfuncs.sh: No such file or directory
/dwh_Loadfuncs.sh

May i please know why variable $BIN_DIR is not initialized?

Thank you.
never mind i got the answer thank you.
# 2  
Old 02-12-2014
I presume it's because the variable hadn't been exported? It's helpful if you tell us how you solved your problem.
# 3  
Old 02-12-2014
Quote:
Originally Posted by Scott
I presume it's because the variable hadn't been exported? It's helpful if you tell us how you solved your problem.
I put a line to source .bashrc file.
HTML Code:
#!/bin/bash
. ~/.bashrc
echo "Bin Dir: ${BIN_DIR}"
. "${BIN_DIR}"/dwh_Loadfuncs.sh
# 4  
Old 02-13-2014
You wouldn't need to source the .bashrc if the variable had been exported.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[solved] sed append into .bashrc

Hi all, I'm trying to do a basic append into /home/joe/.bashrc: /usr/bin/test -z `sudo /bin/grep umask /home/joe/.bashrc` && sudo /bin/sed -i '/PATH=/a \ umask 0022 ' /home/joe/.bashrc I run this as user floren with full root privileges in sudoers. For some reason, the first command is... (1 Reply)
Discussion started by: TECK
1 Replies

2. Shell Programming and Scripting

[solved] awk: placement of user-defined functions

Hi folks, is there any recommendation, especially from a point of performance, about where to place a user-defined function in awk, like in BEGIN{} or if it is only need once at the end in END{}? Or doesn't it matter at all since, awk is so clever and only interprets it once, wherever it is... (3 Replies)
Discussion started by: zaxxon
3 Replies

3. Shell Programming and Scripting

[Solved] Output in bash script not captured in variable

I'm tring to write down a simple script that would execute a command and wait until it returns a specific result. This is what i did: bjobs_out=`bjobs` while ]; do bjobs_out=`bjobs` sleep 6 done It seems to work until the command 'jobs' return the list of jobs in execution, but... (4 Replies)
Discussion started by: lifedj
4 Replies

4. UNIX for Dummies Questions & Answers

[Solved] startxwin and .bashrc problem

On my old computer I always used "startxwin.bat". This worked well and when it was executed an xterm window would open and the .bashrc file in my /home/username/ folder had been read correctly and all of my aliases worked. However with the newest version of Cygwin I noticed that startxwin.bat is... (3 Replies)
Discussion started by: lemmy
3 Replies

5. Shell Programming and Scripting

AWK variable in Main script??? solved

Using an awk script , i want to store the value of a variable in the main script. currently sum is getting reset to blank in the main script. How to modify the below code to get the value of esum in the variable sum of the main script??? sum=`echo "$row" | awk -F"" '{$esum=$5}'` ... (0 Replies)
Discussion started by: skyineyes
0 Replies

6. Shell Programming and Scripting

Finding Variable Value defined in a Script

Hi , I had a script in which there is a variable $LOG defined and I want to check where that variable is getting value from, is there a way I can check for that variable and it's value if it is defined in some other script function or script . I checked using command env and also export... (1 Reply)
Discussion started by: somu_june
1 Replies

7. Shell Programming and Scripting

.bashrc files modifying the PS1 variable?

Is there a command for finding all files on the system named ".bashrc" that modify the PS1 variable? I'd like to list the full file name(s) and the protection (including the full path). (5 Replies)
Discussion started by: raidkridley
5 Replies

8. Shell Programming and Scripting

reading ~/.bashrc variable

1) I've added a variable called IMPORT_HOME to my ~/.bashrc file: IMPORT_HOME=/import:$IMPORT_HOME 2) I sourced the bashrc file: source ~/.bashrc 3) In my bash script, i tried to echo out the IMPORT_HOME variable but it doesnt print out '/import/, only whitespace: #!/bin/bash echo... (2 Replies)
Discussion started by: nuGz
2 Replies

9. Shell Programming and Scripting

Replace variable with a user defined variable

I have a file that has a list of entries in a column x z z z x y z The column can have any length and any number of any strings. I need to replace each unique string with a user defined number. I can filter the unique entries out using awk '{if (NF==5) print $2}' file | uniq | nl >... (1 Reply)
Discussion started by: ce124
1 Replies

10. Shell Programming and Scripting

problem in getting the path of environment variable set in bashrc in my shell script

hi all i have joined new to the group. i have set an variable in my bashrc file. .bashrc PROGHOME=/home/braf/braf/prog export PROGHOME but while using it in my shell script its path is not taken and i had to explicitly give the export command to set the path. in my script... (8 Replies)
Discussion started by: krithika
8 Replies
Login or Register to Ask a Question