postitional parameters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting postitional parameters
# 1  
Old 03-30-2010
postitional parameters

Is it possible and how would you use postional parameter to prompt user input?

I want to ask the user a question like the following:

Code:
Enter the tablespace_name to backup:

Read the response if it is 2,3, or so on ..

parse the answer into a statement like:

Code:
restore datafile 2, 3;

Is this possible if the user enters 2 or 3 or 4 tablespace_names?
# 2  
Old 03-30-2010
you can do that with read.

Code:
echo "Enter the tablespace_name to backup:"
read val1 val2
echo $val1 $val2

you might require some checks as per your requirement.
# 3  
Old 03-30-2010
No. It has to be dynamic.

It could be 2 vars or 3 vars or more.
# 4  
Old 03-30-2010
Code:
#!/bin/bash
read foo junk
echo $foo
echo  $junk


$ ./t foo junk rest

foo junk rest
foo
junk rest

Or:
Code:
#!/bin/bash
read foo
set $foo
echo $1 $2 $3 etc.

./t foo junk rest more
foo junk rest more
foo junk rest etc.


Last edited by Scott; 03-30-2010 at 06:11 PM.. Reason: Added code tags
# 5  
Old 03-30-2010
positional parameters and loading an array

How about this

HTML Code:
print "enter the tablespace_names: "

read INPUT

array=$(echo -e "$INPUT")

print ${#array[*]}
print  ${array[*]}
If I read the values into a variable like INPUT ( that would hold users, tools, and so on ) what is the must efficient way to chop that variable up and populate the array?

thanks.
# 6  
Old 03-30-2010
Try with the -a option of read
Code:
echo "Enter the tablespace_name(s) to backup:"
read -a TBLS
for ((i=0; i<${#TBLS[@]}; i++))
do
    echo "$i ${TBLS[$i]}
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting parameters

Hi, I have 2 scripts one master.sh and child.sh. The master runs on a separate server and pushes the child script to the desginated server and runs it.The child script configures the designated server for our day to day use and it has lot of interactive questions which help the... (4 Replies)
Discussion started by: a12ka4
4 Replies

2. UNIX for Advanced & Expert Users

parameters file

Hi, on AIX 6.1 I have a shell script that calls another shell which have some parameters. Say like the following : ##This is main script############ myparameters.sh command1 command2 ..... .... And here myparameteres.sh : export ORACLE_SID=MYDB export... (6 Replies)
Discussion started by: big123456
6 Replies

3. Shell Programming and Scripting

Playing with parameters

Can someone help me of doing something like this send.sh #!/bin/bash for last; do true; done echo $* | gammu sendsms TEXT $last every thing is good except that when i launch the script like this ./send.sh This is the message i want to send +63922XXXXXXX it turned out the message of... (2 Replies)
Discussion started by: arturo322
2 Replies

4. AIX

tuning network parameters : parameters not persist after reboot

Hello, On Aix 5.2, we changed the parameters tcp_keepinit, tcp_keepintvl and tcp_keepidle with the no command. tunrestore -R is present in inittab in the directory /etc/tunables we can clearly see the inclusion of parameters during reboot, including the file lastboot.log ... (0 Replies)
Discussion started by: dantares
0 Replies

5. Shell Programming and Scripting

More than nine parameters

Hi, please tell me the systax for passing 11 variables(including 4compulsory variables) in shell program. ORA_USERPASS=`echo $1` USERID=`echo $2` USERNAME=`echo $3` REQUESTID=`echo $4` P5=`echo $5` P6=`echo $6` P7=`echo $7` P8=`echo $8` P9=`echo $9` shift P10=`echo $9` shift... (3 Replies)
Discussion started by: anitha126
3 Replies

6. Shell Programming and Scripting

parameters

i'm supposed to come up with a script that -accepts a directory as an optional command line parameter -display an error message and terminates if more than one parameter is provided -use the current directory if no parameter is provided -displays an error message and terminates if the provided... (4 Replies)
Discussion started by: jaay
4 Replies

7. HP-UX

Need to look at Kernel parameters

Hello all, Can anyone tell me the command line I can use to look at the following Kernel parameters: nfile maxfile maxfile_lim I'm using the Reflection manager connection to my Unix box so I can't use SAM. (3 Replies)
Discussion started by: impunchdrunk
3 Replies

8. Shell Programming and Scripting

Input parameters

I have a script which take 3 input parameters 1st - a date (i.e. current date) 2nd - type (i.e. A) 3rd - limit (i.e. 40) normally the date parameter would be current date, so I thought I could do this calculate.sh $(date +%Y-%m-%d) A 40 however, it seems like it can't be done,... (3 Replies)
Discussion started by: mpang_
3 Replies

9. Shell Programming and Scripting

parameters

I have a script that needs to check if the given parameters are a combination of 0123456789 and not a word or another irelevant character.please help (6 Replies)
Discussion started by: aekaramg20
6 Replies

10. Shell Programming and Scripting

Need Parameters Help.

I can test for one parameter but anything more then that and I get an Error. I forgot I run this batch in a shell #!/bin/sh ------------------------------------------------------------------------- Write a batch program that accepts a keyword as a parameter and finds all the files... (3 Replies)
Discussion started by: james2006
3 Replies
Login or Register to Ask a Question