Script variable help, Varying number of arguments to excute script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script variable help, Varying number of arguments to excute script
# 1  
Old 06-02-2013
Script variable help, Varying number of arguments to excute script

Hi Guy's.

Hopefully someone can help me with what I am trying to archieve.

So situation currently is, I have a script already setup however I have another script that sits infront of it.

The main script basically goes and searchs multiple platforms for a list of entered data.

In order to set off the second script i need to be able to read the list of entered data and then enter it in a certain format. Details below

user enters the list of details for checking in the below format as an example

Code:
NO1
NO2
NO3
NO4
NO5

When they press enter the command needs to format it as per below

Code:
./scriptname NO1 NO2 NO3 NO4 NO5

This will then work and is what I currently have working, My issue is they may only have for example 3 bits of data to check however as I have set arguements for 1,2,3,4 and 5 so the script wont run.

Does anyone know how I am able to list the arguments however even if they are not all there still run the script but just not including the missing arguement bits.

Any help you can offer would be much appreciated.

Thanks

Last edited by Scrutinizer; 06-02-2013 at 07:10 PM.. Reason: code tags
# 2  
Old 06-02-2013
Please show us what you have. There are hundreds of ways to do this, but to understand what you're doing and how to give you a working solution for your problem it would help a lot to see what you're doing.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 06-02-2013
Script details

Hi Don,
Thanks for your response, Im fairly new to scripting so I am sure there are alot better ways to try and do what I want however its a learning curve for me so any advice you can offer would be much appreciated.

Example below

Code:
#!/bin/sh
echo "Please enter the MSISDN in 44 format then press the return key"?
read MSISDN
read MSISDN1
read MSISDN2
read MSISDN3
read MSISDN4
read MSISDN5
read MSISDN6
echo " Please wait... "
~/singlemsisdn $MSISDN $MSISDN1 $MSISDN2 $MSISDN3 $MSISDN4 $MSISDN5 $MSISDN6

So basically within this script the user would enter MSISDN's, I would like to do up to 100 at a time so in the above format im sure its going to take forever however Im not sure how else to do it at present. Once the user has entered the MSISDN's it needs to put it in the format of ~/SCRIPTNAME followed by each msisdn entered earlier with a space in between. THe only problem the amount of MSISDN's may vary and in the way I was trying to write it because i have defined more arguments than the amount of data the user entered it wont run.

Format of text the user will enter would be like the below

Code:
441234567890
441234567890
441234567890
441234567890

Hope you get the gist.

If i need to try explain clearer let me know.

cheers

Last edited by Scrutinizer; 06-02-2013 at 07:09 PM.. Reason: more detail; code tags (mod)
# 4  
Old 06-02-2013
What OS are you using? What is the output from the command:
Code:
/bin/sh --version

If /bin/sh is an old Bourne shell, we need to take a different approach than if we can use the arrays that are available when using bash and ksh. Can you use ksh or bash instead of /bin/sh (if /bin/sh isn't already a link to one of those)?

PS. What is 44 format? Would you like the script to validate that values input are in 44 format?
# 5  
Old 06-02-2013
Hi Don,

Output as requested
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)

Not sure if thats enough to answer your question ?

So the user data the user will be inputting is UK mobile numbers... which have to start with 44 (international format). If would be great if it can validate the format prior yes.

Thanks
# 6  
Old 06-02-2013
I generally use ksh, but I can work with bash. Would using ksh instead of bash be OK? (For most shell code, they are identical. But validating phone numbers would be easier for me if I can use some ksh extensions.)

If I understand the UK phone numbering plan, all valid mobile phone and pager numbers in the UK would be in the form +44 7xxx xxxxxx when dialed from the US. Does this agree with what you are expecting?

How do you expect users to enter these numbers:
  1. Is the leading + required (i.e., +44 7xxx xxxxxx or 44 7xxx xxxxxx)?
  2. Are spaces allowed? (If so, are spaces required?) (+447xxxxxxxxx)
  3. If spaces are allowed or required, can the spaces be replaced by minus signs? (+44-7xxx-xxxxxx)
If multiple formats are allowed, what form does singlemsisdn want? Can singlemsisdn take an arbitrary number of operands? Will it only work if given seven operands? Will it only work if given one to seven operands?

How should users indicate that they are done:
  1. Use ctl-D?
  2. Enter q or quit?
  3. Enter an empty line?
  4. Enter 0?
I'm going to be unavailable for most of the afternoon, but if you can answer these questions, I'll take a look at it tonight.

---------- Post updated at 12:49 ---------- Previous update was at 12:40 ----------

Sorry for double posting. I just looked at your previous messages again. Looking for twelve digit numbers starting with 447 will be easy with either bash or ksh. So, ignore the questions about the format of the input, but I still need answers about how to terminate input and how to group entered data when invoking singlemsisdn.

Sorry,
Don
# 7  
Old 06-02-2013
xargs converts lines to arguments. (Is this your problem?)
Code:
echo "Please enter the MSISDN
in 44 format then press Ctrl-D"
xargs ~/singlemsisdn

A loop allows more control of course - but simplicity first!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assigning any number to the variable in cshell script

Hello Guys, I would like to ask you for a favor. Could you please help me how can I assign any number as the parameter to a, from stdin (-c), in the following command line by using the 'switch' in a script? awk '$8>a {print "File name:" $5,$8}' I would also appreciate if you can share any... (1 Reply)
Discussion started by: Padavan
1 Replies

2. Shell Programming and Scripting

Bash script to give multiple choices and a varying number of answers

Hello everybody, I use `case' quite a lot but , excellent as it is , it only gives one final result ; can anyone suggest a way whereas , say long lists of choices are given and I , or a user could select either one two or any number of results to be echoed . many thanks in... (3 Replies)
Discussion started by: V686
3 Replies

3. Shell Programming and Scripting

Number of arguments to array - Perl Script

I have the following proc. proc get_add {arg1 arg2 arg3 arg4 arg 5 .. ... arg N } { } i need to count the number of arguments and also i need those arguments stored in an array. please help out ---------- Post updated at 06:33 PM ---------- Previous update was at 05:30 PM ---------- ... (1 Reply)
Discussion started by: Syed Imran
1 Replies

4. Shell Programming and Scripting

Login, excute command, logout Script Help

Good Evening all, After spending the last week or so reading many posts I decided to register and join in. This is my first post on the forum so please forgive me as im new to this, Im after some help in throwing together a quick basic script without using expect to change the password on several... (4 Replies)
Discussion started by: mutley2202
4 Replies

5. Shell Programming and Scripting

Needed value after the last delimeter in a file with varying number of delimited columns

Hi All, My file has the records as below: aaa\bbb\c\dd\ee\ff\gg zz\vv\ww pp\oo\ii\uu How can I get the value after the last delimeter. My o/p: gg ww uu Thanks in Advance, (5 Replies)
Discussion started by: HemaV
5 Replies

6. Shell Programming and Scripting

Looking for help with script to assign all disk space to slice#0 on multiple disks of varying sizes

Hi Folks, I am trying to make a script to assign all diskspace to slice 0, on multiple sized disks. Since the disks are new they may need to be labelled also to avoid the error: Cannot get disk geometry Below is my code struggling with logic which doesn't seem to be producing the desired... (0 Replies)
Discussion started by: momin
0 Replies

7. Shell Programming and Scripting

How to call arguments with variable in a script??

Hello, I was wondering if it were possible to call arguments passed to a script using a variable. For example: sh script.sh yes no good bad x=$# while do echo (last argument, then second last etc until first argument) let x=($x-1) done should print out bad good no (4 Replies)
Discussion started by: VanK
4 Replies

8. Shell Programming and Scripting

Varying number of awk search strings

I've created an awk script that handles a varying number of search strings handed to it as command line parameters ($1 $2 etc). There may be 1, or 2 or 3 or more. A simplified version of the script is: awk -v TYP="$1 $2 $3 $4 $5 $6" ' BEGIN { CTYP = split (TYP,TYPP," ") } ... (2 Replies)
Discussion started by: CarlosNC
2 Replies

9. Shell Programming and Scripting

replacing a number with random variable inside shell script

Hi All. I need help for the below logic. I ve a file like following input file: NopTX(5) // should be remain same as input ----Nop(@100); //1 Nop(90); //2 --Nop(80); //3 @Nop(70); //4 --@Nop(60); //5 @Nop@(@50); //6 --Nop@( 40); ... (3 Replies)
Discussion started by: user_prady
3 Replies

10. Shell Programming and Scripting

is there any way to excute script every N seconds?

Hello i have script that show me stuff , i need to excute this script every N seconds , is there any way to do it with one liner ? ( mybe perl ) thanks (7 Replies)
Discussion started by: umen
7 Replies
Login or Register to Ask a Question