0

Hi all,

I have a problem I always though i knew the answer to.

I have a variable with spaces and I want to perform an operation on each.

VAR="THIS" "THAT" "THIS AND THAT" "THIS AND THIS"

for i in $VAR
do
echo "$i"
done

I thought that I should be able to use $i in speech marks for this "$1" but it doesn't work and I don't seem to be able to suss it out.

Any ideas?

thanks

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by cfajohnson
0

VAR="THIS" "THAT" "THIS AND THAT" "THIS AND THIS"

You can not assign variables as such. However you can VAR="THIS THAT THIS AND THAT THIS AND THIS" Nevertheless, I feel you probably do not want that since it can not make a distinction for "sentences" like "THIS AND THAT"

Maybe what you want is an array of sentences.

var=( "THIS" "THAT" "THIS AND THAT" "THIS AND THIS" )

for i in "${var[@]}"; do
    echo $i
done

Edited by Aia: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.