Sponsored Content
Top Forums Shell Programming and Scripting Putting strings into positioning array in loop Post 303022228 by annacreek on Tuesday 28th of August 2018 11:26:03 AM
Old 08-28-2018
Maybe.

Here is the debug output as code is being processed.

It looks to me that each pass add next string and than debug prints the whole file.

But it builds multiple "strings"and it really does not matter how.

I did add the "index" so I can "see" the progress.


Thanks



Code:
+ set -- 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description '
+ echo 'index  10'
index  10
+ for i in {0..16..2}
+ set -- 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description '
+ echo 'index  12'
index  12
+ for i in {0..16..2}
+ set -- 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description '
+ echo 'index  14'
index  14
+ for i in {0..16..2}
+ set -- 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description ' 'CLI command' 'CLI command description '
+ echo 'index  16'
index  16
+ pause
+ read -p 'Press [Enter] key to continue...'
Press [Enter] key to continue...

------ Post updated at 10:26 AM ------

OK. the code does the job. Many thanks.


Minor problem - now I need to copy the positioning array to a file.

This simple verification code does reads the array in reverse.
It would make things easier if I could add the lines into the file starting with 1 and go up.



I suppose I can change the while[condition] and check for # for != 16 in this case.

Or can I start from $# = 1 and shift "up" ?


Code:
testLoopAddition(){
  55 for i in {0..16..2}
  56 do 
  57    set -- "$@" "CLI command" "CLI command description "
  58    echo "index  $i"     
  59 done
  62 echo "In reverse start with $# positional parameters"
  63 # while positional parameter not empty 
  64 while [ "$1" != "" ]; do
  65     echo "Parameter $# equals $1"
          copy $1 to file here 

  68     shift
  69 done

 

10 More Discussions You Might Find Interesting

1. Programming

array of strings

Hi I need a better idea to implementing following in my code. I need to store 80 long strings that will be used to display one by one in my GUI application. now i am storing those 80 long string in following two dimentational array. uchar vpn_alm_long_str={ } each index will be an... (1 Reply)
Discussion started by: davidcreston
1 Replies

2. Shell Programming and Scripting

How to run a loop for assigning strings which are present in a file to an array

Hi Forum, I am struggling with the for loop in shell script. Let me explain what is needed in the script. I have a file which will conatin some strings like file1 place1 place2 place3 checkpoint some other text some more text Now what my requirement is the words ... (2 Replies)
Discussion started by: siri_14
2 Replies

3. Programming

Multidimensional array of strings with vector.

I've been struggling with this for quite some time. I decided I should get some help with this. Nothing is working. I'm getting a segmentation fault or out of bounds error when I try to load the entries in the for loop.I'm really frustrated. :mad: Compiling isn't the problem. It's crapping out on... (5 Replies)
Discussion started by: sepoto
5 Replies

4. Programming

C; storing strings in an array

I am trying to get userinput from stdin and store the lines in an array. If i do this: using a char **list to store strings allocate memory to it #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { char *prog = argv; char **linelist; int... (5 Replies)
Discussion started by: tornow
5 Replies

5. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

6. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

7. Shell Programming and Scripting

Taking information from a postgres sql query and putting it into a shell script array

I have a postgres sql statement that is the following: select age from students; which gives me the entries: Age --- 10 15 13 12 9 14 10 which is about 7 rows of data. Now what I would like to do with this is use a shell script to create an array age. As a results... (3 Replies)
Discussion started by: JSNY
3 Replies

8. Shell Programming and Scripting

How to strip some characters before putting in array?

Hi Gurus, my current code like below: nawk '{f1 = (NF>1)?$1:""}{print f1, $NF}'|sed -e 's/s(/,/g;s/)//g;s/ *,/,/'|nawk -F"," '{ab}END{for (i in b) if (!(i in a))print i}' I have file like below. (this is autosys job dependencies) the job with s() is dependencies, the job without s() is... (10 Replies)
Discussion started by: ken6503
10 Replies

9. Shell Programming and Scripting

Help tabulating file putting repeated strings as headers

Hi. May somebody help me with this. I´m trying to tabulate the following input file, but the desired output I´m getting is incorrect. I have access to GNU/LINUX (Ubuntu) and Cygwin Input file STAGE = 1 ID = 0 NAME = JFMSC TYPE = MLRR DFRUL = PERMISSION ADDR = 1001 RRUL =... (10 Replies)
Discussion started by: Ophiuchus
10 Replies

10. Shell Programming and Scripting

Passing positioning array as whiptail -- menu option

I may have asked this before, so forgive OF. Problem: I can pass positioning array as -- menu option to whiptail, but it does not show in the whiptail form as an array - only single (first member "lsusb" ) entry / line shows up. Code: DynamicEntry=$(whiptail \ --title "DEBUG... (1 Reply)
Discussion started by: annacreek
1 Replies
Excel::Template::Container::Loop(3pm)			User Contributed Perl Documentation		     Excel::Template::Container::Loop(3pm)

NAME
Excel::Template::Container::Loop - Excel::Template::Container::Loop PURPOSE
To provide looping NODE NAME
LOOP INHERITANCE
Excel::Template::Container ATTRIBUTES
o NAME This is the name of the loop. It's used to identify within the parameter set what variables to expose to the children nodes each iteration. CHILDREN
None EFFECTS
None DEPENDENCIES
None USAGE
<loop name="LOOPY"> ... Children here ... </loop> In the above example, the children nodes would have access to the LOOPY array of hashes as parameters. Each iteration through the array would expose a different hash of parameters to the children. These loops work just like HTML::Template's loops. (I promise I'll give more info here!) There is one difference - I prefer using Perl-like scoping, so accessing of variables outside the LOOP scope from within is perfectly acceptable. You can also hide outside variables with inner values, if you desire, just like Perl. AUTHOR
Rob Kinyon (rob.kinyon@gmail.com) SEE ALSO
perl v5.14.2 2012-04-29 Excel::Template::Container::Loop(3pm)
All times are GMT -4. The time now is 09:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy