Unix Shell - Re: bash: var contains full line. How to input this data with spaces

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > March 2005 > Re: bash: var contains full line. How to input this data with spaces





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: bash: var contains full line. How to input this data with spaces
Ed Morton

2005-03-28, 6:18 pm



stevenbentley@yahoo.com wrote:

> Hi again,
> I have a variable that contains
> VAR1='one "two three" four' and i would like to store these in the
> following
>
> VAR2=one
> VAR3="two three"
> VAR4=four
>
> I have the following:
>
> VAR1='one "two three" four'
> echo ${VAR1} | awk '{ print $2 }'


PS1> VAR1='one "two three" four'
PS1> echo "${VAR1}" | awk -F\" '{ print $2 }'
two three

PS1> echo "${VAR1}" | gawk 'BEGIN{RS="\""}$1=$1'
one
two three
four

PS1> eval `echo "${VAR1}" |
gawk 'BEGIN{RS="\""}$1=$1{printf "VAR%s=\"%s\"\n",NR,$0}'`
PS1> echo "$VAR1"
one
PS1> echo "$VAR2"
two three
PS1> echo "$VAR3"
four

> but as I'm sure you reliase i get: "two
> Is this the best method (with fixes!) or ...?
>
> I'm having real problems with quoting at the moment!!!


Hope that helps,

Ed.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com