1

I am attempting to build a zenity interface calling one of a bunch of scripts located in a specific folder. For this, I am relying on zenity --list. I want the list to have two columns: 1) script filename and 2) description text [from the third row's comment, within the script file itself].

I can make a single-column for a filename-only interface, without a problem. The problem here comes up when I wish to use a second column for description, trying to mimick the following example:

zenity --list \
  --title="Choisissez les bogues à afficher" \
  --column="N° de bogue" --column="Gravité" --column="Description" \
    992383 Normal "GtkTreeView plante lors de sélections multiples" \
    293823 Grave "Le dictionnaire GNOME ne prend pas de proxy en charge"     \
    393823 Critique "L'édition de menu ne fonctionne pas avec GNOME 2.0"

More simply, I would like to understand why the two following set of commands do not provide similar results, from a terminal:

$ zenity --list   --title="Choose script" --column="Script" --column="Description" a.sh "chaise longue" b.sh "moineau"

and

$ TESTSTRING='a.sh "chaise longue" b.sh "moineau"'
$ echo $TESTSTRING
a.sh "chaise longue" b.sh "moineau"
$ zenity --list   --title="Choose script" --column="Script" --column="Description" $TESTSTRING

3 Answers 3

5

Quotes within a quoted string don't matter to the shell that's doing the field splitting. They're just like any other character. So, when you use $TESTSTRING instead of "$TESTSTRING", the quotes within - those surrounding chaise longue and moineau - do not prevent field splitting:

$ TESTSTRING='a.sh "chaise longue" b.sh "moineau"'
$ printf "%s\n" $TESTSTRING 
a.sh
"chaise
longue"
b.sh
"moineau"

If you want to retain your desired splitting, use arrays:

$ TESTSTRING=(a.sh "chaise longue" b.sh "moineau")
$ printf "%s\n" "${TESTSTRING[@]}"
a.sh
chaise longue
b.sh
moineau
1

Quote each variable, like so:

zenity --list   --title="Choose script" --column="Script" --column="Description" "a.sh" "chaise longue" "b.sh" "moineau"

enter image description here

0

Dynamic List with MySql

I use this code for a project in my school that can you use

#!/bin/bash
arg="-u user -pPass -D Database -s -e"

function lista(){
gerentes=$(mysql $arg "SELECT * FROM empleado;")
OIFS=$IFS;
IFS=$'\n';       
array=($gerentes)

for ((i=0; i<${#array[@]}; ++i));
do
 IFS=$'\t'
 cont=(${array[$i]})
 for ((j=0; j<${#cont[@]}; ++j));
 do      
     echo -n -e "${cont[$j]}" | tr -d '[[:space:]]'
     echo -n -e "\t"
 done
 IFS=$OIFS;
done
IFS=$OIFS;
}

First, I define a function 'lista' and call it in the zenity code

OP=$(zenity --list \

 --title="Seleccione Gerente" \
 --column="id" --column="Fecha" --column="Nombres" --column="cedula" --column="user" --column="cargo" --column="direccion" \
 $(lista))

 echo "Selecciono: $OP"
1
  • If it works in ubuntu, Confirmed Feb 8, 2017 at 1:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .