Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm really pulling my hair out on this one. I just started with some bash scripting and I'm trying to create a simple script that uses some dialogs to give me a fast way to do a svn checkout. It's working fine untill i want to serve a radiolist with multiple options which are fetched when you enter your project for a checkout.

Here's the last part of the code where it fails:

  if [ $MATCHFOUND = true ]; then
    echo 'Exact match found do checkout'
  else
    if [ ${#repoar[@]} == 0 ]; then
      whiptail --title "Error" \
      --msgbox "No matches found for [$PROJECT]" 8 78
      ./dialog.sh
    else
      for ((i=0; i<${#repoar[@]}; i++))
      do
        RADIOLIST=$RADIOLIST" \"$i\" \"${repoar[$i]}\" \"OFF\""
      done

      let ARLENGTH=${#repoar[@]}
      whiptail --radiolist "Projects found" 20 78 $ARLENGTH "$RADIOLIST"
    fi  
  fi

Example for $RADIOLIST

 "0" "test" "OFF" "1" " test 5" "OFF" "2" " test2" "OFF" "3" " test3" "OFF" "4" " test4" "OFF"

The Radiolist arguments do no seem to get escaped like they should when i add the variable as parameter arguments. When i copy past the example using the whiptail command it works fine.

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

Quotes get interpreted before variables are substituted, so embedding quotes in variable values doesn't do anything useful. If I understand what you're trying to do properly, the easiest way to do it is to use an array for RADIOLIST:

RADIOLIST=()
for ((i=0; i<${#repoar[@]}; i++))
do
    RADIOLIST+=("$i" "${repoar[$i]}" "OFF")
done

let ARLENGTH=${#repoar[@]}
whiptail --radiolist "Projects found" 20 78 $ARLENGTH "${RADIOLIST[@]}"
share|improve this answer
    
Thx! this does the trick. –  Michael Jul 5 '11 at 21:14
add comment

Looks like you need to change

RADIOLIST=$RADIOLIST" \"$i\" \"${repoar[$i]}\" \"OFF\""

To

RADIOLIST=$RADIOLIST" \\\"$i\\\" \\\"${repoar[$i]}\\\" \\\"OFF\\\""

This will insert a \ before each " in the generated output, resulting in the desired escaping in the call to whiptail a few lines later.

share|improve this answer
    
I'm currently giving this a try but still seems to fail. –  Michael Jul 5 '11 at 20:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.