I have the below code which works . I need to extend it by iterating thru the array arr and executing a command in each loop. some thing on the lines of below.
I need to run this in a Jenkins script , so I would need below
bash script to run interactively in the command line
an escaped version to run in Jenkins build
This does not work . basically does not execute
pids=(2567538 2356789); export pids;echo "pid = ${pids[*]}";arr=($(echo "${pi
ds[*]}" | tr " " "\n")); echo "arr = ${arr[*]}" ; for pid in $arr do echo $pid
done;
>
Bash version details
$ bash -version
GNU bash, version 4.4.12(1)-release (x86_64-pc-msys)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
The shell has a special variable you can set, IFS, to change its internal delimiter. It is not any sort of regex, only a list of characters which are valid "splitters". By default it is space, newline, and tab. It's only used for variable quoting purposes and some builtins like read. So:
OLDIFS="$IFS" ; IFS=","
VAR="1,2,3,4,5,6,7,8,9,10"
for X in $VAR
do
echo $X
done
The examples above use the GO template to format in JSON format. I strongly recommend that you install the command line utility jq to use with this output. Not only does it allow for readable formatting of the JSON, but it allows for drilling down into the data more easily than just reading the output. For example, the keywords of the output of docker images :