i need to add 2 string variables into a positioning array , repeatedly - in loop.
First string in $2, second to $3 then up to the desired count incrementing the "position".
Using set -- alone does not increment the count so I end up with 2 variables in the array.
The positional parameters are limited in the sense that it can only be filled in one go, either by passing them to a script of function or using the set command.
So you can only manipulate the this to set the positional parameters, for example:
The empty string as the first parameter put the other strings in position 2 and 3.
But then the number of elements is not accurate, because echo "$#" will report 3
But why don't you use a regular array, available in bash or ksh? Then you can put strings in any position you like.
In this case the the elements arr[0] and arr[1] remain unused
Last edited by Scrutinizer; 08-26-2018 at 04:00 AM..
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
------ 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.
How do you intend to copy these to a file? Is it one per line to the same file? If so, you could look at the bash built-in printf:
This will print your parameter list as a list of space-separated strings, one per line, until your list is exhausted. Try this noddy program:
This might not be what you want, of course. As we were putting spaces in the parameters in the above examples you may prefer this:
Basically, if you give printf more arguments than it needs it will use as many as it can and then repeat with the next set until the list is exhausted. So if you wanted to print two parameters per line, use
instead.
I am still trying to understand how bash code is executed.
Perhaps my perception of code line executing "left to right" is basically wrong.
Look at line #277
Every "manual" I read about using "wc" states it "prints".
I do not need "print" - I need to process what I am used to call "function return value".
OK, I understand 'wc" "prints" most likely to some "stdxxx" - as output of "pipe" .
So how does lineCount value , being at the "front" of the pipe get assigned?
And why is the file to be analyzed at the "end" of the code line?
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)
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)
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)
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)
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)
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)
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)
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)
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)