Creating an array with options as an argument!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating an array with options as an argument!
# 1  
Old 04-05-2013
Creating an array with options as an argument!

Hi Guys,
I am writting a c shell script where I have to parse an input argument with options that could be an array. So far I have achieved where I could parse a single argument with option but failed when I try to create an array with the options. For example:
This is on terminal window: temp.csh A B C D -Tbase
Code:
set array = ()
@ i = 0
while ($i <= ${#argv})
     switch ($argv[$i])
     case -T*:
             set th = `echo $argv[$i] | awk '{print substr($1,3)}'`
     breaksw
     default:
     set array = ($array $argv[$i])
     endsw
     @ i++
end
set lst = $array[1]
set out = $array[2]
set t =  $array[3-] ##This could also be an array

The above code works for single string after -T option but if I want to create an array :example -Tbase 0.2scrub , it fails. Can anybody help please?
Also on aside note if I want a space between -T base 0.2scrub , how can I change my script?
Thanks in advance!
# 2  
Old 04-05-2013
I wont touch the C shell if i were you...read here why not.
# 3  
Old 04-05-2013
This is a small part of a long code written in c shell. My task is to modify this part. I am slowly shifting to bash but this part requires me to modify the code in c shell.

---------- Post updated at 12:38 PM ---------- Previous update was at 11:06 AM ----------

Please if anybody figure out than please let me know ASAP!

Last edited by dixits; 04-05-2013 at 04:22 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Creating file and passing argument to a command

Hi All, I am having command to run which will take argument as input file. Right now we are creating the input file by cat and executing the command ftptransfer -i input file cat >input file file1 file2 cntrl +d Is there a way I can do that in a single command like ... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

2. Shell Programming and Scripting

Creating array from file

Dear community, how can I create an array from file taking only the 4th field? out.txt file is something like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20So the final array should be: 4 8 12 16 20With this command I created an array with all the fields, but I need only the 4th... (13 Replies)
Discussion started by: Lord Spectre
13 Replies

3. UNIX for Dummies Questions & Answers

Creating an array

I am having trouble creating an array, I've tried everything google gives me but it won't work, and it seems as though it should. Using Ubunto 12.04 and bash. #!/bin/bash ARRAY=one two three echo ${ARRAY}When I do this I receive the error : two: not found and : Bad substitution When I... (3 Replies)
Discussion started by: jrymer
3 Replies

4. UNIX for Advanced & Expert Users

Creating a Custom ISO with Options

Here is the scenario: At work I have been ask to create a custom ISO using UBUNTU as the chosen distro, install our prerequisted packages and present the customer with a choice of options of enabling and disabling services and just in general custom choices that I want to present to the user... (2 Replies)
Discussion started by: metallica1973
2 Replies

5. Shell Programming and Scripting

Array as argument

hi I've 2 bash script, in the first i define an array and I'd like to pass it as argument to the second script. For example: first_bash: k=(1 2 3 4) ....... #in the end i call the 2 script ./second_bash $k then in the second_bash: ..... echo "${1}" #this not work but i'm... (7 Replies)
Discussion started by: Dedalus
7 Replies

6. Programming

Creating an array to hold posix thread ids: Only dynamic array works

I am facing a strange error while creating posix threads: Given below are two snippets of code, the first one works whereas the second one gives a garbage value in the output. Snippet 1 This works: -------------- int *threadids; threadids = (int *) malloc (num_threads * sizeof(int)); ... (4 Replies)
Discussion started by: kmehta
4 Replies

7. Shell Programming and Scripting

creating a dynamic array

i want to create an array the array elements are populated depending upon the number of entries present in a data file The data file is created dynamically how to achieve the same thanks (1 Reply)
Discussion started by: trichyselva
1 Replies

8. Shell Programming and Scripting

Associated array from command line options

I am looking to populate an (associated) array with a command line argument. The command line would look something like this: alert -action test -priority '10' -module test_module . . . The associated array would look like this after the data is read in flag=(action=test priority=10... (1 Reply)
Discussion started by: jperret
1 Replies

9. UNIX for Dummies Questions & Answers

array as command line argument !!!!

hello, can any help me how to can pass array as command line argument in korn shell. also how to read a array from command line. thanks spandu (2 Replies)
Discussion started by: spandu
2 Replies

10. Shell Programming and Scripting

shell: creating different arrays based on function argument

hi, I was wondering if there was a good way to create an array within a function, where the name is based on a passed argument? I tried this: _____________________________ func(){ #take in 1st arg as the arrayname arrayName=$1 let i=0 while read line do arrayName=${line} let i+=1... (5 Replies)
Discussion started by: nix21
5 Replies
Login or Register to Ask a Question