Define Variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Define Variables
# 1  
Old 08-14-2016
Define Variables

Hi,

I just define the variable in script and use those script in another script but the variable not recognize.

test1.sh
Code:
   #!/bin/bash
   DB="test_db"
   USR="test_user"
   PWD="test_pwd"
   HST="24.254.87.12"

test2.sh
Code:
   #!/bin/bash
   ./test1.sh
   mysql -u $USR -p $PWD -h $HST $DB


To execute here got some error

Code:
./test2.sh
mysql: option '-h' requires an argument

Any work around to make it work?


Very strange, because when i put all together in one script it work. My purpose of putting into one script just to call more of my scripts those loaded variables in test1.sh.

Thanks in advanced!


Regards,
FSPalero



Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 08-15-2016 at 04:24 AM.. Reason: Added CODE tags.
# 2  
Old 08-15-2016
use . or source command

Code:
#!/bin/bash
. test.sh
mysql -u $USR -p $PWD -h $HST $DB


or


#!/bin/bash
source test.sh
mysql -u $USR -p $PWD -h $HST $DB

# 3  
Old 08-15-2016
Hi itkamaraj,

Working now, you save my work.

Thank you very much/

Regards,
Ferdie

Last edited by fspalero; 08-15-2016 at 02:00 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

When to define functions in C?

Hey everyone. So I'm looking at a few C programming resources, and it seems, by convention how you should write and define a function, is first declare it's existence before your main...then call it somewhere in your main, and then define after, at the end of the program? Is this necessary? I mean... (7 Replies)
Discussion started by: Lost in Cyberia
7 Replies

2. Shell Programming and Scripting

Using a script to define variables and run multiple other scripts in succession.

I'm pretty new to scripting in Korn shell so please forgive me... What I'm trying to do is to create a script that calls multiple other ksh scripts and defines variables for text files. I need it to define my user defined variables (file paths, date & time stamps, etc that are currently in... (1 Reply)
Discussion started by: bluejwxn8
1 Replies

3. Shell Programming and Scripting

Loop to define variables in KSH

Hi, I am trying to use a database to store configurations in an environment definition scripts to make the configurations easily modifiable. (long story short - it is an easier process to make changes in the db than trying to deploy a file). The values will be stored in the database in the... (1 Reply)
Discussion started by: gbala
1 Replies

4. UNIX for Dummies Questions & Answers

Define variables with UNIX script

oopps! I Meant "Define Variables within a UNIX Script" What would be the best way to define a variable in a unix shell script so anyone who views this script doesn't know what value is assigned to that variable. some other location... a="/usr/lib/fileA" Unix script... sed... (5 Replies)
Discussion started by: macastor
5 Replies

5. Programming

#define in c

Hi, I had a head file, looks like #define MIN_NUM 10 #define MAX_NUM 10 is there any way to get "MAX_NUM" from 10? thanks. peter (9 Replies)
Discussion started by: laopi
9 Replies

6. Programming

help with #define in C

if i do this in C #define NUM 1234512345 then how come i cant print it out using int main(int argc, char **argv) { printf("%d\n", NUM); return 0; } well the result is -1219236538, why isnt it 1234512345 ? (7 Replies)
Discussion started by: omega666
7 Replies

7. Programming

#define

Hello, I would like to conditionaly comment in my code source some fields from arrays. So I use the property ## from the #define definition. my code: ... #define slet /##* #define etsl *##/ ... const T_SVT_ADLL_A653_DESC A_DESC = { { slet qwerty etsl SLICING,... (3 Replies)
Discussion started by: cypleen
3 Replies

8. UNIX for Dummies Questions & Answers

#define in perl

Hi friends, I am not sure if perl questions can be raised here. :rolleyes: But I have a doubt if there is a way to do "#define" in perl, like in C. Does anyone know if it is feasible (without CPAN modules)? Thanks, Srini (7 Replies)
Discussion started by: srinivasan_85
7 Replies
Login or Register to Ask a Question