Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need some help with Yad. This is my code:

contact=$(while read line
                firstname=$(echo $line | awk 'BEGIN { FS="|" } { print $2 }')
                lastname=$(echo $line | awk 'BEGIN { FS="|" } { print $3 }')
                num=$(echo $line | awk 'BEGIN { FS="|" } { print $4 }')
                birthday=$(echo $line | awk 'BEGIN { FS="|" } { print $5 }')

                if [  $firstname != ""  -a  $lastname != "" ] ; then
                    echo "$firstname$lastname"
                    if [ $firstname != "" ] ; then
                        echo "$firstname,"
                    elif [ $lastname != "" ] ; then
                        echo "$lastname"
                        echo "$num"

            done < "contactlist.txt" )
idlist=$(while read line
                idnum=$(echo $line | awk 'BEGIN { FS="|" } { print $1}')
                echo $idnum
            done < "contactlist.txt" )

sortcontact=$(printf "%s\n" $contact | sort)

selected=$(yad --title="Contacts" --width=200 --height=200 --button="DISPLAY:2" --button="ADD:3" --list --separator=""  --column="List" $sortcontact --column="ID:NUM" $idlist)

The output in $idlist and $sortcontact are all mixed up.

I want that the column ID should only have the $idlist while the column list should only have the $sortcontact.

share|improve this question
And what is yad? – Oli Jan 21 '14 at 13:04
Yad stands for "Yet another dialog" – joanne_ Jan 21 '14 at 13:06
I'd be happy to help but I've got nothing to test against. Could you set up your code so instead of it parsing files, it's just yad running static data? And on the plus site, if that works, you know where the problem is. – Oli Jan 21 '14 at 13:16
up vote 3 down vote accepted

I don't know yad, but it's apparently a fork of zenity, so you probably need to feed it the items the same way as with zenity; name1 id1 name2 id2 instead of name1 name2 id1 id2.

Something like this should be close to what you want, I think.

#!/usr/bin/env bash
while IFS='|' read -r idnum firstname lastname num birthday _; do
    if [[ $firstname || $lastname ]]; then
        items+=( "$firstname $lastname" "$idnum" )
        items+=( "$num" "$idnum" )
done < <(sort -t'|' -k2 contactlist.txt)

selected=$(yad --title=Contacts --width=200 --height=200 \
               --button=DISPLAY:2 --button=ADD:3 --list \
               --separator= --column=List --column=ID:NUM \
share|improve this answer
Thank youuu! that worked perfectly! Plus you made the code simpler!! – joanne_ Jan 21 '14 at 14:17

Your Answer


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.