Find the answer to your Linux question:
Results 1 to 4 of 4
Hello, I'm trying to write a simple script to back up all jpeg and png files from removable media in a graphical way using zenity as a bit of an ...
  1. #1
    Just Joined!
    Join Date
    Feb 2009
    Posts
    1

    need help with simple zenity script

    Hello,

    I'm trying to write a simple script to back up all jpeg and png files from removable media in a graphical way using zenity as a bit of an exercise I've set myself.

    I've reached a bit of a brick wall and can't understand the result I'm getting from a command so wsa hoping someone could help.

    Cutting out superfluous stuff (like titles, text etc...) what I have in a nutshell is this;
    Code:
    #!/bin/bash
    #
    Medlist=`ls -1 -I cdrom0 /media | while read File; do echo "FALSE $File"; done`
    #
    ans1=$(zenity --list --title="Select Storage Device(s)" --text="Here is the list of removable storage devices." --checklist --multiple --separator="," --column " " --column "Removable Storage" $Medlist)
    Now when I try to use find on the output in the next line like so;

    Code:
    ans2=`find /media/{$ans1} -name "*.jpg" -or -name "*.png"`
    #
    echo $ans2
    I get an error saying find: file '/media/{disk,disk-1,etc}' not found.

    If I enter the find command directly into the shell however, it works fine. I can't see why it isn't working as part of the script as the syntax in the error message seems fine.

    Any ideas?

    -JimDog*-

  2. #2
    Just Joined!
    Join Date
    Oct 2004
    Posts
    62
    Hi,
    I didn't replay to your request to leave space to the Linux gurus and above all because I hadn't
    understood your problem.
    After 3 weeks I see that you still have 0 replays... I hope that you, in the meantime, have solved
    your problem by yourself! .
    If it's not the case... we can solve it ... starting however on more infos.
    As I get it, you need a script to backup jpg & png files from removable media (CD. DVD, floppy,
    pendrives or USB External drive)... what is zenity for?
    Try before to solve your problem w/out zenity (which at max here has visualization purposes....)
    To test zenity you should test the single dialogs alone...
    Bye.

  3. #3
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    It would be nice if variable expansion works in the scenario you describe but unfortunately it doesn't. My work-around is not that pretty but it should work (basically it just expands the $ans1 variable "manually").
    Code:
    OLD_IFS=$IFS
    IFS=','
    target=''
    for d in $ans1; do target="/media/$d $target"; done
    IFS=$OLD_IF
    
    ans2=`find $target -name "*.jpg" -or -name "*.png"`
    #
    echo $ans2

  4. #4
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    Well it seems my conclusion was too early. I've got the solution for you:

    Code:
    ans2=`eval find /media/{$ans1} -name "*.jpg" -or -name "*.png"`
    #
    ans2=`echo $ans2`
    PS: I learned the trick from [ Internal Commands and Builtins , section eval ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...