Reading arguments for a shell script from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading arguments for a shell script from file
# 22  
Old 01-12-2012
If you run this script from a terminal, you should be able to read < /dev/tty to use the terminal directly without bothering stdin. /dev/tty is a special device which opens whatever device is your controlling terminal.

If you run this without a terminal, this will of course malfunction...
This User Gave Thanks to Corona688 For This Post:
# 23  
Old 01-12-2012
Quote:
Originally Posted by Corona688
If you run this script from a terminal, you should be able to read < /dev/tty to use the terminal directly without bothering stdin. /dev/tty is a special device which opens whatever device is your controlling terminal.

If you run this without a terminal, this will of course malfunction...
Thanks Corona. The script is indeed run from a terminal. I will try this in my script.

---------- Post updated at 07:06 PM ---------- Previous update was at 06:53 PM ----------
I tried it and it works a charm. cheers

Last edited by goddevil; 01-12-2012 at 03:14 PM..
# 24  
Old 04-15-2012
Quote:
Originally Posted by Corona688
I don't understand the problem. Variables you set in the external file the way methyl suggests can indeed be used in your program.
Thanks. For your reply here.i have the same issue. But. I am not able to read from the file the same way. Is this external file supposed to b in some format.what I did was aa

Parm.txt has following contents
User="abc"
Pwd="password"
Export $User $Pwd

And script.ksh has
User=$1
Pwd=$2

Then I executed

./script.ksh ./Parm.txt

But it's not working. Please suggest. Thanks in advance.
# 25  
Old 04-17-2012
Quote:
Originally Posted by maverick1947
Thanks. For your reply here.i have the same issue. But. I am not able to read from the file the same way. Is this external file supposed to b in some format.what I did was aa

Parm.txt has following contents
User="abc"
Pwd="password"
Export $User $Pwd

And script.ksh has
User=$1
Pwd=$2

Then I executed

./script.ksh ./Parm.txt

But it's not working. Please suggest. Thanks in advance.
You dont need to export the variables $User and $Pwd. Just executing the parm script will export the variables.

Consider that there are two files:
Parm.sh
User="abc"
Pwd="password"

script.ksh
Your code

If you want to inherit the values of User and Pwd from the parm.sh into script.ksh, there are two ways to go about doing it:

1. Execute the parm.sh script before executing the script.ksh from the terminal.
$ ./parm.sh
$ echo $User $pwd
$ ./script.ksh

2. The better, more preferred option will be to invoke the parm.sh and its values from within script.ksh as follows:

script.ksh
. ./parm.sh
echo $User $Pwd
**Your code***

In the above example, the variables User and Pwd will be inherited by the script
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Passing Arguments to shell script from file is not working as expected.

Hi All, I have below simple shell script in cloudera quick start vm cenos 6 which copy file from source to destination. # file_copy.sh source_dir = ${source_dir} target = ${target_dir} cp source_dir target and my parameter file is like below #parameter_file.txt source_dir =... (4 Replies)
Discussion started by: Narasimhasss
4 Replies

2. UNIX for Beginners Questions & Answers

Shell script file check throws [: too many arguments

While I am trying to check the filename/s in IF statement of a shell script (RedHat Linux 6) I am getting below error: File check: filename_time2=`date --date='yesterday' +%Y-%m-%d` cd /location/of/the/files/to/copy if then cp server.log-$filename_time2* ../archive/new... (5 Replies)
Discussion started by: Dip
5 Replies

3. Shell Programming and Scripting

php file unable to run shell script with arguments

echo $result=exec("./permit.sh".$_FILES); pls suggest some other method to run shell script in php .:wall::mad: (0 Replies)
Discussion started by: upvan111
0 Replies

4. Shell Programming and Scripting

Error while reading from a file in shell script

Hi All, I'm writing a script to read a file line by line and then perform awk function on it. I am getting an error . My file has one name in it "James". I'm expecting my o/p to be youareJamesbond James ./users.sh: line 7: =: command not found #script to read file line by line #adding... (5 Replies)
Discussion started by: Irishboy24
5 Replies

5. Shell Programming and Scripting

send arguments to a .exe file from a shell script

Folks , can anyone post a sample showing a way to parse a variable containing a string to a .exe file . Thanks Venu (2 Replies)
Discussion started by: venu
2 Replies

6. Shell Programming and Scripting

How to pass arguments to SQL file passed in shell script?

Hi, I am using SYBASE database. in my script i am connecting to DB via using isql. isql -U${S_USER} -S${S_SERV} -D${S_DB} -P${S_PWD} -b0 -w3000 -h0 -s"|" -i${MYDIR}/ABC.sql -oXYZ.txt << FINSQL i am taking a ABC.sql file to use the queries written in it and storing the output in... (3 Replies)
Discussion started by: dazdseg
3 Replies

7. Shell Programming and Scripting

file reading through shell script

For reading a file through shell script I am using yhe code : while read line do echo $line done<data.txt It reads all the line of that file data.txt. Content of data.txt looks like: code=y sql=y total no of sql files=4 a.sql b.sql c.sql d.sql cpp=n c=y total no of c files=1 (4 Replies)
Discussion started by: Dip
4 Replies

8. Solaris

Passing arguments to a shell script from file while scheduling in cron

Hi, I have a shell script Scp_1.sh for which I have to pass 2 arguments to run. I have another script Scp_2.sh which in turns calls script Scp_1.sh inside. How do I make Scp_1.sh script to read arguments automatically from a file, while running Scp_2.sh? -- Weblogic Support (4 Replies)
Discussion started by: weblogicsupport
4 Replies

9. Shell Programming and Scripting

Reading file names from a file and executing the relative file from shell script

Hi How can i dynamically read files names from a list file and execute them from a single shell script. Please help its urgent Thanks in Advance (4 Replies)
Discussion started by: anushilrai
4 Replies

10. UNIX for Dummies Questions & Answers

Reading runtime arguments from a file

Hi All, I am running a script which wud take a long time to complete execution ... In between, it asks for yes/no sort of confirmation from user for doing some acivities .... Now that I dont want to wait till the script executes upto this point where it needs user confirmation, is there any way... (4 Replies)
Discussion started by: Sabari Nath S
4 Replies
Login or Register to Ask a Question