Reading values from the command line


 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications Reading values from the command line
# 1  
Old 05-04-2010
Reading values from the command line

Hi

I want to give the user the choice of whether or not they want to include a certain option when they run the script.

This is my getops:

Code:
while getopts " s: d: r f: e h " option
do
case $option in

f ) dsxfile="$OPTARG";;
d ) dbname="$OPTARG";;
s ) dsn="$OPTARG";;
r ) rangechk="-O";;
e ) verbose="--verbose";
reverb="--echo";;
h | ? | * ) displayHelp;exit;;

esac;
done

This is my variables:

Code:
dbname="$dbname"
dsn="$dsn"
dsxfile="$dsxfile"
rangechk="$rangechk"
verbose=""
reverb=""
module=`basename $0`
dsxdir="/var/local/dsx/import"
dsximp="/usr/local/bin/dsximp.exe"
dsxpids="/var/run/"

Example, this is how I run the script:

Code:
./dsximp --$rangechk --dsn=$dsn --dbname=$dbname --user=datasafe --password=datasafe --dsxfile=$dsxdir/$dsxfile

Basically, the user can specify whether or not they want to add the option rangechk

If they do, the script will be called with that option included, if they don't, then they can omit that option....

The variable rangechk is initialised to "-O"

How do I add it in my script to make it such?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace values in script reading line by line using sed

Hi all, Let's say I have a script calling for the two variables PA_VALUE and PB_VALUE. for pa in PA_VALUE blah blah do for pb in PB_VALUE blah blah do I have a text file with two columns of values for PA and PB. 14.5 16.7 7.8 9.5 5.6 3.6 etc etc I would like to read this... (7 Replies)
Discussion started by: crimsonengineer
7 Replies

2. Shell Programming and Scripting

Command line arguments with multiple values

how can I pass multiple values from command line arguments example script.sh -arg1 op1 -arg2 op1 op2 op3 (2 Replies)
Discussion started by: nsk
2 Replies

3. Shell Programming and Scripting

Reading of variable in a single line command

Hi All, Below is a sample command that I can run without any problem in the command line. Command Line dtToday=`date +%Y%m%d`; ls -ltr ./filename_${dtToday}.txt -rw-r--r-- 1 monuser oinstall 0 Jan 18 11:02 ./filename_20130118.txt But once I put that command line in file (list.txt) and... (3 Replies)
Discussion started by: padi
3 Replies

4. Programming

Reading command line arguments and setting up values if option not provided

I have a C++ program. I read command line arguments, but if the value is not supplied, I default or make a calculation. Let's say I set it to a default value. I can code this in several ways. Here I show three ways. What would be the best way for maintaining this code? The program will get very... (2 Replies)
Discussion started by: kristinu
2 Replies

5. Shell Programming and Scripting

Reading command line options from bash script

I have the following code and I am calling it using ./raytrac.bash -u and getting problems. For some reason opt_usage is still 0. opt_usage=0 iarg=0 narg=$# while (($iarg < $narg)) do (( iarg = $iarg + 1 )) arg=$argv usrInputFlag=`echo $arg | awk '/=/ {print 1}; ! /=/... (22 Replies)
Discussion started by: kristinu
22 Replies

6. Shell Programming and Scripting

help with reading command line into array

set -A title set -A author count=1 index=0 while do read -A ${title}?"Booktitle: " read -A ${author}?"Author(s): " (( count = count + 1 )) (( index = index + 1 )) done Hi... (1 Reply)
Discussion started by: bjhum33
1 Replies

7. UNIX for Advanced & Expert Users

Reading putty command line parameters from Linux

I am running Putty 0.60 from Windows XP and I am connecting to a Linux box. I would like to be able to pass a command line parameter to my Linux session so that my Linux session can execute a specific command, depending on the command line parameter. I have looked on the Internet and tried... (1 Reply)
Discussion started by: SFNYC
1 Replies

8. Shell Programming and Scripting

Storing Command Line Values

Hi, I am trying to read the value passed by the user and store it in a variable so that later I can read it from the variable. But I am getting errors. Can you please help? Thanks. Code: $ECHO "Enter the Country for which you want the installation to be executed? (US/India):" read COUNTRY... (3 Replies)
Discussion started by: yoursdavinder
3 Replies

9. Shell Programming and Scripting

reading ps command's output line by line

hi; as a pseudo; while read psLine do myFunc $psLine done < ps i don't want to redirect ps command's to a file. in fact, my problem is "how can i read stdout line by line in bash, sed, awk or any?" thanks, (5 Replies)
Discussion started by: s. murat
5 Replies

10. Shell Programming and Scripting

Bash: Reading 2 arguments from a command line

If no arguments are entered I wanna be able to read 2 arguments, i have done like this but it doesnt work: x=0 until #loop starts do if ; then echo No arguments were entered, please enter 2 arguments. read $1 $2 elif || ; then echo $#... (0 Replies)
Discussion started by: Vozx
0 Replies
Login or Register to Ask a Question