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

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
var='"THIS" "THAT" "THIS AND THAT" "THIS AND THIS"'

eval "set -- $var"

for i
do
  echo $i
done
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.