This is a snippet of my script:
#!/bin/bash
list="ann 1 bob 2 cat 3 dog 4"
for i in $list; do
-a-a-a echo-a $i
done
This outputs the strings from the list, one per line, thus:
ann
1
bob
2
cat
3
dog
4
But I would like to output just the alternate values, thus
ann
bob
cat
dog
So I want to add a line, a bit like this:
#!/bin/bash
list="ann 1 bob 2 cat 3 dog 4"
for i in $list; do
-a-a-a echo-a $i
-a-a-a next i
done
How do I achieve the line "next i" , please?
Ultimately I want to process the list entries in pairs, but I don't want to overcomplicate my question at present.
This is a snippet of my script:
#!/bin/bash
list="ann 1 bob 2 cat 3 dog 4"
for i in $list; do
echo $i
done
This outputs the strings from the list, one per line, thus:
ann
1
bob
2
cat
3
dog
4
But I would like to output just the alternate values, thus
ann
bob
cat
dog
So I want to add a line, a bit like this:
#!/bin/bash
list="ann 1 bob 2 cat 3 dog 4"
for i in $list; do
echo $i
next i
done
How do I achieve the line "next i" , please?
Ultimately I want to process the list entries in pairs, but I don't want
to overcomplicate my question at present.
On 8/4/26 8:18 AM, Graham J wrote:
This is a snippet of my script:Good ole Copilot:
#!/bin/bash
list="ann 1 bob 2 cat 3 dog 4"
for i in $list; do
-a-a-a-a-a echo-a $i
done
This outputs the strings from the list, one per line, thus:
ann
1
bob
2
cat
3
dog
4
But I would like to output just the alternate values, thus
ann
bob
cat
dog
So I want to add a line, a bit like this:
#!/bin/bash
list="ann 1 bob 2 cat 3 dog 4"
for i in $list; do
-a-a-a-a-a echo-a $i
-a-a-a-a-a next i
done
How do I achieve the line "next i" , please?
Ultimately I want to process the list entries in pairs, but I don't want
to overcomplicate my question at present.
list=(ann 1 bob 2 cat 3 dog 4)
for ((i=0; i<${#list[@]}; i+=2)); do
-a-a-a echo "${list[i]}${list[i+1]}"
done
printing the pairs.-a-a Just remove the ${list[i+1]} if you only want the ann,bob,cat,dog parts.
How do I achieve the line "next i" , please?
Ultimately I want to process the list entries in pairs, but I don't want to overcomplicate my question at present.
I don't think this is achieving much, but at least I got
the selected elements to print out. I used this for the starting point
https://stackoverflow.com/q/8880603/loop-through-array-of-strings-bash
( also https://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html )
#!/bin/bash
declare -a arr=("ann" "1" "bob" "2" "cat" "3" "dog" "4")
for i in `seq 0 2 6`
do
echo "${arr[i]}"
done
$ ./test.sh
ann
bob
cat
dog
Paul
#!/bin/bashGood ole Copilot:
list="ann 1 bob 2 cat 3 dog 4"
for i in $list; do
-a-a-a-a-a echo-a $i
-a-a-a-a-a next i
done
How do I achieve the line "next i" , please?
Ultimately I want to process the list entries in pairs, but I don't want
to overcomplicate my question at present.
list=(ann 1 bob 2 cat 3 dog 4)
for ((i=0; i<${#list[@]}; i+=2)); do
-a-a-a echo "${list[i]}${list[i+1]}"
done
printing the pairs.-a-a Just remove the ${list[i+1]} if you only want the ann,bob,cat,dog parts.
Good ole Copilot:
list=(ann 1 bob 2 cat 3 dog 4)
for ((i=0; i<${#list[@]}; i+=2)); do
-a-a-a-a echo "${list[i]}${list[i+1]}"
done
printing the pairs.-a-a Just remove the ${list[i+1]} if you only want
the ann,bob,cat,dog parts.
That looks worth a try.-a It's very like what I tried using an array (see
my reply to Paul in the ng) so I will test it this evening and let you
know.
Or one of those problems, where you spend four hours figuring out
"how many back-slashes will this require to work". And you're up to
eight back-slashes and wondering what's for lunch. Sure, eventually
you might stumble on the syntax, but you'll be a lot older and
grayer. And if someone asks you "whats the deal with these eight
back slashes", you tell them "I don't know, I just kept adding them
until the error messages stopped".
Graham J wrote:
[snip]
Good ole Copilot:
list=(ann 1 bob 2 cat 3 dog 4)
for ((i=0; i<${#list[@]}; i+=2)); do
-a-a-a-a echo "${list[i]}${list[i+1]}"
done
printing the pairs.-a-a Just remove the ${list[i+1]} if you only want
the ann,bob,cat,dog parts.
That looks worth a try.-a It's very like what I tried using an array (see >> my reply to Paul in the ng) so I will test it this evening and let you
know.
Tried, it works OK. Thanks.
On 2026-08-04, Graham J <nobody@nowhere.co.uk> wrote:It makes it's mistakes there too but for the most part it's good. I use it for stuff
Graham J wrote:AI can not be poor at everything, writing code seems to be the exception to the rule.
[snip]
Good ole Copilot:
list=(ann 1 bob 2 cat 3 dog 4)
for ((i=0; i<${#list[@]}; i+=2)); do
-a-a-a-a echo "${list[i]}${list[i+1]}"
done
printing the pairs.-a-a Just remove the ${list[i+1]} if you only want
the ann,bob,cat,dog parts.
That looks worth a try.-a It's very like what I tried using an array (see >>> my reply to Paul in the ng) so I will test it this evening and let you
know.
Tried, it works OK. Thanks.
On 2026-08-04, Graham J <nobody@nowhere.co.uk> wrote:
Graham J wrote:
[snip]
Good ole Copilot:
list=(ann 1 bob 2 cat 3 dog 4)
for ((i=0; i<${#list[@]}; i+=2)); do
echo "${list[i]}${list[i+1]}"
done
printing the pairs. Just remove the ${list[i+1]} if you only want
the ann,bob,cat,dog parts.
That looks worth a try. It's very like what I tried using an array (see >>> my reply to Paul in the ng) so I will test it this evening and let you
know.
Tried, it works OK. Thanks.
AI can not be poor at everything, writing code seems to be the exception to the rule.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 74 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 51:09:58 |
| Calls: | 1,100 |
| Files: | 1,339 |
| Messages: | 276,012 |