[Bradford] bash hell , removing " from a strings

Martyn Ranyard ranyardm at gmail.com
Sun Jun 28 23:58:16 UTC 2009


Hi Dick,

  What I would be tempted to do is something like the following (bear in
mind that with unix there's umpteen million ways to skin a cat) :

#!/bin/bash

select="\"foo\" \"bar\" \"lemon\" \"cheese\""
echo "original is : $select"
count=$(echo $select | sed s/\"//g | wc -w)
echo "count is $count"

for f in $(seq 1 $count); do
  export $(echo $select | sed s/\"//g | cut -f$f -d' ')="\
    $(echo $select | sed s/\"//g | cut -f$f -d' ')"
done

echo $foo
echo $bar
echo $lemon
echo $cheese

which should output :
original is : "foo" "bar" "lemon" "cheese"
count is 4
foo
bar
lemon
cheese

Perhaps not the neatest or most elegant way but it uses tools I'm familiar
with and didn't require much thinking.  Hopefully I've understood the
desired result as well.  Using export may also not be a good thing, but I
remember that echo "value" | read var doesn't set $var, and can't remember
another way around that.

Hope that helps,
--
Martyn

On Sun, Jun 28, 2009 at 11:33 PM, Dick Thomas <xpd259 at gmail.com> wrote:

> I'm writing a bash script and i'm stuck
>
> the out put of a dialog menu is
>
> echo $select
> "foo" "bar" "lemon" cheese"
>
> while I need
> $foo $bar $lemon $cheese
>
> to reuse them as strings later in the script
> and very new to bash scripting and i've no idea how to do this
> any help would be fantastic
>
> Dick
>
> <code>
> dialog --backtitle "Enable / Disable Tags" \
>                --no-cancel --title "CHECKLIST BOX" \
>                --checklist "Hi, blah blah fill me in" 25 61 15 \
>                "$CITY"  "$CITY_TAG" off \
>                "$COPYRIGHT"    "$COPYRIGHT_TAG" off \
>                "$Orange" "$orange_tag" off \
>                "$Chicken"    "$chicken_tag" off \
>                "$Cat"    "$CAT_TAG" off\
>                "$Fish"   "$FISH_TAG" off \
>                "$Lemon"  "$LEMON_TAG" on 2> $tempfile2
>
>        retval=$?
>
>        enable=`cat $tempfile2`
>
> echo $enable
> </code>
> "foo" "bar" "lemon" "poo-sticks"
>
> _______________________________________________
> Bradford mailing list
> Bradford at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/bradford
>


More information about the Bradford mailing list