Reading Variables From another file

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.
sameer666
Naik
Posts: 82
Joined: Tue Nov 06, 2007 5:31 am

Post by sameer666 »

my appologies

Code: Select all


#!/bin/bash

echo Please enter your first name:
read fname
echo Please enter your last name:
read lname

touch info.log

echo -e "Fname=$fname\nLname=$lname\n" >> info.log

cat info.log | while read line;

do

echo | awk '

{

print substr ("'"$line"'",7,20)

}'

done
Fname=$fname
export Fname #makes and an environmental variable
/bin/bash        #invoke child bash shell with Fname set


should work now
Novice at heart
mudasir
Captain
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Location: Dubai
Contact:

Post by mudasir »

AOA,

Sameer bhai i can not test it right now...light chali gaye [:d]
As soon as electricity comes back i will try....
by the way sameer bhai the following code is printing the values of the variables

echo | awk '

{

print substr ("'"$line"'",7,20)

}'

i dont want it to print the values...
I am very sorry i might be irritating you, sorry...
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
sameer666
Naik
Posts: 82
Joined: Tue Nov 06, 2007 5:31 am

Post by sameer666 »

hey

you can modify the code to suit your needs, it is just to show u howto.

just remember to

1) export variable
2) call new bash
3) variable should have some value set, or u will not have any environmental variable.

the new bash invoked will have a environmental variable set to wat ever value u set it to.
Novice at heart
mudasir
Captain
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Location: Dubai
Contact:

Post by mudasir »

AOA,

Dear Sameer 1 last question.
If i want to call this variable in another script do i only have to use only this code

Code: Select all

cat info.log | while read line; 

do 

echo | awk ' 

{ 

print substr ("'"$line"'",7,20) 

}' 

done 
Fname=$fname 
export Fname #makes and an environmental variable 
/bin/bash        #invoke child bash shell with Fname set 
Thanks alot for helping me out
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
Post Reply