I recently was handed responsibility for a script which has array references that are new to me and I could use some help understanding them.
Parts of the config file and script are included. This script collects backups from a jail server of the jails running on that host. Several jail servers are backed up.
In the first config file the collect0_backup_host="host.xxx.net" refers to the jail host.
It is the syntax of collect0_backup_host that throws me. collect0 is translated to
$collect${N} in the script -- this part I understand -- but the _backup-host (variable?)
that is appended to collect0 is confusing me. I've never seen an array defined this way before and could use some useful links or explaination of how this works.
Thanks
thumper
Last edited by Scott; 09-16-2010 at 05:20 PM..
Reason: Replaced ICODE tags with CODE tags
This is construction that is used if a shell in question does not know arrays. The way it is used in the script that you were handed, is a bit cumbersome. Instead of
this could be used:
eval works like this: first everything after eval is passed as parameter to eval. The shell processes the variable ${N}. The first $ is escaped ( \$ ), so that it is not treated as a special character. So after processing the command eval gets the following string (suppose N=1):
end then executes this. As a result you would get:
Last edited by Scrutinizer; 09-16-2010 at 06:32 PM..
hello,
i need a bit of help on how to do this effectively in bash without a lot of extra looping or massive switch/case
i have a long array of M elements and a short array of N elements, so M > N always. M is not a multiple of N.
for case 1, I want to stretch N to fit M
arrayHuge
H = (... (2 Replies)
Trying to do some control flow parsing based on the index postion of an array member. Here is the pseudo code I am trying to write in (preferably in pure bash) where possible. I am thinking regex with do the trick, but need a little help.
pesudo code
if == ENDSINFIVEINTS ]]; then
do... (4 Replies)
Hi!
Let's say I would like to convert "1", "2", "3" to "a", "b", "c" respectively. But if a record contains other number then return "X".
input:
1
2
3
4
output:
a
b
c
X
What is the syntax for:
if(array doesn't contain a particular index){
then print the value "X" instead} (12 Replies)
Please help me out: I've seen this construct
awk '{...}1'several times, like in scrutinizer's today's post
awk '{for(i=2;i<=NF;i++)if($i==$1)$i=RS $i}1' infilebut I can't find (manuals, man pages, internet FAQs,...) an explanation of what it does resp. stands for. Any hint is appreciated! (5 Replies)
I have an array and two variables as below,
I need to check if $datevar is present in $filename.
If so, i need to replace $filename with the values in the array.
I need the output inside an ARRAY
How can this be done.
Any help will be appreciated. Thanks in advance. (2 Replies)
Hi All,
I'm writing a nagios check that will see if our ldap servers are in sync...
I got the status data into a nested array, I would like to search key of each array and if "OK" is NOT present, echo other key=>values in the current array to a variable
so...eg...let take the single array... (1 Reply)
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)
I was checking my error logs today and ran into some errors I have not seen before maybe somebody has run into these before?
/etc/cron.quarter-hourly/owusers.sh:
Set effective gid to mail(12) failed!
/usr/local/mailwatch/check_sendmail_relay.sh: line 8:
thanks (1 Reply)