LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-28-2008, 05:37 AM   #1
RudraB
Member
 
Registered: Mar 2007
Distribution: Fedora
Posts: 264

Rep: Reputation: 23
reading variables from other file


i have two shell script.
the nrec is declared once in first script as:
echo -e "Number of Recursion step\nThe default value is 30"
read nrec

And the second one is
#!/bin/bash
#This script manages the Results mostly by
#creating seperate files for each orbital
#from the main o/p ab.dat
for ((i=1; i<=9; i++))
do
cnt=`expr $i \* $nrec`
#echo "$cnt"
head -$cnt RESULT/ab.dat|tail -$nrec>RESULT/$i.dat
done


is there any way to pass the variable nrec of first script to the 2nd one without reading it once again??
 
Old 03-28-2008, 06:06 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
If the second script is launched from the first, you can use export to make the variable available to all the processes launched from the first script, e.g.
Code:
#!/bin/bash
echo -e "Number of Recursion step\nThe default value is 30"
read nrec

export nrec=$nrec
/path/to/second_script.sh
in this case the second script inherits the variable nrec from the environment.

Instead, if the two scripts are launched separately, I think the only way is that the first script writes the value of nrec somewhere in a file and the second script waits for the file creation and then read the value of nrec (and eventually deletes the file).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create a new file including content from reading another file !? silverhand Programming 2 10-06-2007 04:33 PM
Reading/Wirting file/parsing xml file using javascript fakhrul Programming 1 08-14-2007 05:08 PM
Reading text file-writting binary file cdog Programming 5 06-13-2006 11:56 AM
BASH script – reading and writing variables to a separate file morrolan Programming 10 09-20-2005 07:45 AM
awk: fatal:cannot open file for reading (no such file or Directory) in Linux sangati vishwanath Linux - Software 4 07-06-2005 12:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration