• yad > les Fonctions

      FONCTIONS

      yad --button=gtk-ok:"bash -c on_click" --button=gtk-help:"bash -c help" --button=gtk-quit:0

       

      Pour appeler des fonctions dans un script :

       

      #! /bin/bash
      
      on_click(){
         yad --about
      }
      export -f on_click
      
      help(){
         yad --text=" This is help file. "
      }
      export -f help
      
      yad --button=gtk-ok:"bash -c on_click" --button=gtk-help:"bash -c help" --button=gtk-quit:0

       

      VARIABLES

      Pour exporter des variables, la tâche est un peu compliquée :

       

      #!/bin/sh
      names=$(echo "Waters,Gilmour,Wright,Mason")
      occupation=$(echo "Basse,Guitare,Claviers,Drums")
      yad --form --separator="," --item-separator="," --field="Qui:":CB --field="Quoi:":CBE --field="Blabla:":TXT \
      "$names" "$occupation" "qui fait quoi ?"


       

      Si on appuie sur OK, le retour sera > Waters,Basse,qui fait quoi ?,

       

      #!/bin/sh
      names=$(echo "Waters,Gilmour,Wright,Mason")
      occupation=$(echo "Basse,Guitare,Claviers,Drums")
      yad --form --separator="," --item-separator="," --field="qui:CB" --field="quoi:CBE" --field="blabla:TXT" \
      "$names" "$occupation" "Type your comments here" | while read LL ; do
         NAME=`echo $LL | awk -F',' '{print $1}'`
         OCCUPATION=`echo $LL | awk -F',' '{print $2}'`
         COMMENT=`echo $LL | awk -F',' '{print $3}'`
         echo "(The selected name) (Selected occupation) (Comments)"
         echo
         echo $NAME $OCCUPATION $COMMENT
      done

       

      Ou :

       

      #!/bin/sh
      names=$(echo "Waters,Gilmour,Wright,Mason")
      occupation=$(echo "Basse,Guitare,Claviers,Drums")
      yad --form --separator="," --item-separator="," --field="qui:CB" --field="quoi:CBE" --field="blabla:TXT" \
      "$names" "$occupation" "Type your comments here" > /tmp/config
      NAME=`cat /tmp/config | awk -F',' '{print $1}'`
      OCCUPATION=`cat /tmp/config | awk -F',' '{print $2}'`
      COMMENT=`cat /tmp/config | awk -F',' '{print $3}'`
      #echo $NAME $OCCUPATION $COMMENT #to be run first to work properly with copy/paste into term, in a script it works ok
      echo "(The selected name) (Selected occupation) (Comments)"
      echo
      echo $NAME $OCCUPATION $COMMENT

       

      Ou :

       

      #!/bin/sh
      names=$(echo "Waters,Gilmour,Wright,Mason")
      occupation=$(echo "Basse,Guitare,Claviers,Drums")
      yad --form --separator="," --item-separator="," --field="qui:CB" --field="quoi:CBE" --field="blabla:TXT" \
      "$names" "$occupation" "Type your comments here" | while read LL ; do
         echo "NAME='`echo $LL | awk -F',' '{print $1}'`'" > /tmp/config
         echo "OCCUPATION='`echo $LL | awk -F',' '{print $2}'`'" >> /tmp/config
         echo "COMMENT='`echo $LL | awk -F',' '{print $3}'`'" >> /tmp/config
      done

       

 

Aucun commentaire

 

Laissez un commentaire