Escaping quote marks

Cameron Hutchison lists at
Fri Nov 20 22:54:22 UTC 2009

Ray Parrish <crp at> writes:


>I have the following code which I would like to improve.

>    URLs=""
>     while read ThisLine; do
>           case "$ThisLine" in
>                *\<loc\>*) # if line starts with <loc> concatenate it 
>into string variable URLs.
>                         URLs="$URLs $ThisLine";;
>           esac
>     done < "$MapName"
>     # Prompt user with drop down list of urls to select one to remove 
>from site map.
>     SelectedLine=`Xdialog --stdout --title "Add URL to Site Map - 
>Remove URL" --combobox "Select web page to remove from site map" 10 70 

>The problem is that if any of the iines starting with <loc> contain 
>spaces in their file names, the combobox presents them broken up at the 
>spaces on separate lines in it's drop down list.

If you are using bash, then you can use arrays to hold the URLs such
that each URL can contain spaces and you can still distingish individual

Arrays allow you to use out-of-band separators between elements, instead
of trying to come up with a character that can be used to separate
elements and hoping that the character does not appear in your data.

Something like this (untested):


while read ThisLine ; do
  case "$ThisLine" in
      URLs=("${URLs[@]}" "$ThisLine") ;;
done < "$MapName"

SelectedLine=$(Xdialog --stdout --title "Add URL to Site Map - Remove URL" --combobox "Select web page to remove from site map" 10 70 "${URLs[@]}")

More information about the ubuntu-users mailing list