Running a script with multiple variables like 25 variables.

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running a script with multiple variables like 25 variables.
# 1  
Old 10-11-2013
Running a script with multiple variables like 25 variables.

Hi All,

i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way??

##script is sample.ksh


so while running scripts i have to give like below.

./sample.ksh a13 gM c4 .... tMs

now problem is that position of these arguments can change while passing to script
# 2  
Old 10-11-2013
You can't change the position of positional parameters without changing their "meaning". If you call your script like your second proposal, try
for i in "$@"; do case $i in a*) age=${i:1};; g*) gender=${i:1};; ... etc ... esac; done

# 3  
Old 10-14-2013
You also need to be away that referring to positional parameter $25 will usually end up being interpreted as ${2}5, i.e. the value of parameter two, followed by the literal value 5.

Someone in their wisdom here managed to code scripts that look like this:-

The idea being that the month is passed in as positional parameter 2 and the year is appended. Apart from looking awful, of course we then ended up editing the script each year - oh, and the year was not necessarily the calender year that the process was running in either.

It works for us (very badly and will be replaced soon) but you might get very confused by the use of:-
echo $title

.... giving you the output gM5

# 4  
Old 10-14-2013
The standards state that positional parameters with more than a single decimal digit must be specified with braces. I.e., ${25} will expand to the value of the 25th positional parameter and $25 will expand to the value of the 2nd positional parameter followed by the string 5.

Rather than writing code that uses $25 to append "5" to the expansion of $2, I write it as ${2}5 to make it less likely to confuse people who read my code; but experienced shell programmers should know how this works.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assigning multiple variables in ksh script

Is it possible to have a user input multiple words in one line and have the script assign each word a variable? I'm stuck please assist. Example using "BILL JOHN SARA JILL" as what the user could type: printf "Enter account names: " BILL JOHN SARA JILL read input (9 Replies)
Discussion started by: seekryts15
9 Replies

2. Linux

How to store count of multiple queries in variables in a shell script?

how to store the count of queries in variables inside a filein shell script my output : filename ------- variable1=result from 1st query variable2=result from 2nd query . . . . (3 Replies)
Discussion started by: sanvel
3 Replies

3. Shell Programming and Scripting

Using a script to define variables and run multiple other scripts in succession.

I'm pretty new to scripting in Korn shell so please forgive me... What I'm trying to do is to create a script that calls multiple other ksh scripts and defines variables for text files. I need it to define my user defined variables (file paths, date & time stamps, etc that are currently in... (1 Reply)
Discussion started by: bluejwxn8
1 Replies

4. Shell Programming and Scripting

awk (or other) script that assigns fields from a line to multiple variables

Hey all, Unfortunately I have only basic knowledge of awk and/or scripting. If I have a file with lines that can look similar to this: Name=line1 Arg1=valueA Arg2=valueB Arg3=valueC Name=line2 Arg1=valueD Name=line3 Arg1=valueE Arg3=valueF Name=line4 Arg2=valueG ... (4 Replies)
Discussion started by: Rike255
4 Replies

5. Shell Programming and Scripting

Multiple Variables for BASH script

Hello, I am new to the whole "scripting" thing. Below is the script that I have so far and where i need the Variables to go (VAR#) #!/bin/bash #Sample Script VAR1= echo "Choose an option: 1) Create a file. 2) Delete a file. 3) Move a file." read VAR1 case $VAR1 in 1) echo "Pick... (4 Replies)
Discussion started by: eclerget
4 Replies

6. Shell Programming and Scripting

sql output from multiple rows and columns as variables in a script

This is for an Oracle journal import. I was using a pl/sql package and oracle API's. Oracle added invoker rights to their API's and now my package won't run. I didn't want to use their API's anyway. The only reason i was using pl/sql and the API's (just a package) was to utilize a cursor. How... (2 Replies)
Discussion started by: lmu
2 Replies

7. Shell Programming and Scripting

problem accessing Multiple Variables from C Program to a Shell script

program name--test #!/bin/bash output1=`/home/user/a.c` output2=`/home/user/a.c` k=`$output1 + 1` m=`$output2 + 1` echo $k echo $m --------------------------------------------------------------------------- prgram name--a.c #include<stdio.h> int main() (1 Reply)
Discussion started by: sameworld1980
1 Replies

8. UNIX Desktop Questions & Answers

trying to create a script with multiple variables...

I have created a script that prompts the user to enter three variables that are seperated by a space as the delimiter. It then performs a command 3 seperate times for each variable entered. I want the script to llow the user to enter as many variables as they may like and the script to... (5 Replies)
Discussion started by: Italy87
5 Replies

9. Shell Programming and Scripting

Variables are not getting exported while running the script in cronjob

Hi All Some how, variables are not getting exported while running the script in cronjob. Variable value is coming blank. But the variables are geting the value when the same script I am running manually. Any idea why? When running the script in cron-job ==================================... (7 Replies)
Discussion started by: csaha
7 Replies

10. Shell Programming and Scripting

Pass multiple variables to SQL script

I am trying to close of multiple users in an Oracle database. Each users has records in multiple tables what I need to do is use a script that call each SQL seperately passing either CLI arguments or gathered arguments from the users during run time. ## Accept variable(s) from the command line... (1 Reply)
Discussion started by: jagannatha
1 Replies
Login or Register to Ask a Question