[Solved] Array for parameters from 5th position


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Array for parameters from 5th position
# 1  
Old 12-12-2013
[Solved] Array for parameters from 5th position

Hi All,
I am writing a script where the first 5 parameters are mandatory but the script should be able to handle a maximum of 9 parameters (with the remainig 4 optional)

I would like to load all parameters from 5th parameter positioninto an array.

the piece of code I am writing for this:
Code:
FIL_NUM=`expr $# - 4`
echo "Number of files to transfer: ${FIL_NUM}";
index=0
for fileloop in ${@:5:${FIL_NUM}};
do
echo $index
FIL_NAM[$index]=$fileloop
(( index++ ))
done

Unfortunately this errors out with this
Code:
syntax error near unexpected token `${@:5:${FIL_NUM}}'

Anybody please advise how to make this working.

Thank you!

---------- Post updated at 09:15 AM ---------- Previous update was at 09:09 AM ----------

Hi All, apologise for the follow up but I realised what went wrong. No need to reply. Wanted to remove the thread but couldn't

Last edited by radoulov; 12-16-2013 at 06:07 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

Passing parameters and accepting in Array

I am trying to pass parameters to a script which will accept them in array. First parameter is where_clause second parameter is "SRC_TYPE='SYBASE' and PROCESS_CD='BRK'" } echo $2 $ ./abcd.ksh where_clause "SRC_TYPE='SYBASE' and PROCESS_CD='BRK'" + set -A arg_list -- where_clause... (3 Replies)
Discussion started by: ratheeshjulk
3 Replies

2. UNIX for Dummies Questions & Answers

[Solved] Find position of character with awk

Hi Guys! Could anyone help me with?.. I have a line which says BCVGF%6$#900 .....How can we know which position is for % or say $ by command or script?There is any way to get a prompt by any script? Thanks a lot (6 Replies)
Discussion started by: Indra2011
6 Replies

3. Shell Programming and Scripting

[Solved] Editing the alphabet's based on position information

I do have a file of the following format file 1 >SAM ATGCTCCTTAGCTACGTAGCAAGTAGAAAAAA AGCGCGAGCATTGAAGCGGAGGAGAGGAGGA TGAGATGATGACCCAGTATAAAGAGTGATGAT like this above file. file 1 has 1000's of lines. I would like to edit this file1 using the information from file2 (see below), by... (16 Replies)
Discussion started by: Lucky Ali
16 Replies

4. Shell Programming and Scripting

Grep the 5th and 6th position character of a word in a file

I am trying to find/grep the 5th and 6th position character (TX) of a word in a file. I tried to do grep "....TX" file The output gives me everything in the file with TX in it. I only need the output with the TX in the 5th and 6th position of the word. Any idea Example: test1 car... (5 Replies)
Discussion started by: e_mikey_2000
5 Replies

5. Shell Programming and Scripting

[Solved] KSH: Array/If Help

RedHat 5 KSH I am creating an array, and then using case to go through and count for specific words. Then the count gets stored as an expression. string='ftp rcp rsh telnet ftp ftp' set -A myarray $string FTPCOUNT="0" for command in ${myarray} do case $command in ftp) FTPCOUNT=`expr... (2 Replies)
Discussion started by: nitrobass24
2 Replies

6. UNIX for Dummies Questions & Answers

Find the list of filenames that have the string 31 at 4th and 5th position

Hi, Can anyone let me know the command to know the list of filenames that have string 31 in their 4th and 5th positions inside the file: grep -l "31" main*.txt The above grep lists all the files which have 31 at any position but I want filenames having 31 at position 4 and position 5. (8 Replies)
Discussion started by: okkadu
8 Replies

7. Shell Programming and Scripting

[Solved] I need to parse an username in parameters

Hi! Thank you ina advance for your Help. Sorry my english, Im from Argentina! Great Place!!! So, here si my problem I have a variable, lets say PARAMETERS that could be set like this: PARAMETROS="-Usistemas string1 -Astring2 -G -Y -Kcoco -Y string4 -Z" or PARAMETROS="string1... (1 Reply)
Discussion started by: Hercraft
1 Replies

8. Programming

structure pointer array as function parameters

if i create an array of pointers to a structure "struct node" as: struct node *r; and create "n" number of "linked lists" and assign it to the various struct pointers r using some function with a return type as structure pointer as: r=multiplty(.......) /*some parameters*/ is... (2 Replies)
Discussion started by: mscoder
2 Replies

9. Programming

how to put element of an array to first position.

hi, I have a array like my $array = ( "apple","ball","cat","dog","elephant"); how to push some element in the array to the first position. for example my final array should be elephant apple ball cat dog (5 Replies)
Discussion started by: vprasads
5 Replies

10. Shell Programming and Scripting

call function with different parameters position

Hi I would like to call function in my script couple of times. But each time with different parameters position. In line 57 I don't know how to call it without typing $1 and $ parameters ? #!/bin/ksh 2 3 4 function First 5 { 6 7 # $1 - name 8 ... (2 Replies)
Discussion started by: presul
2 Replies
Login or Register to Ask a Question