LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-11-2019, 01:37 PM   #1
GPGAgent
Member
 
Registered: Oct 2018
Posts: 109

Rep: Reputation: Disabled
BASH - List files to select


I would like to add a file select list to my bash scripts, what methods do you guys use?

I've thought of generating a list, referenced by a number, then all I need to enter is the file number or numbers.

It would be handy to select multiple files as well, or by wildcard.

Happy new year everyone.
 
Old 01-11-2019, 03:04 PM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 10,429
Blog Entries: 7

Rep: Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592
what sort of list?

i think i'd use the shell's tab completion & wildcard functions to pass a list to the script as command line argument(s).

it seems very convoluted to do that inside the script; almost like coding a filemanager.
 
1 members found this post helpful.
Old 01-11-2019, 03:22 PM   #3
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: MacOS, Slackware
Posts: 626

Rep: Reputation: 197Reputation: 197
+1 with ondoho.
I think it can get much more complicated very quickly with numbers because after allowing 1 number, you 'll probably want multiple discrete numbers, then range of numbers, wildcards and so on...
More, all kind of files cannot probably be allowed to be given as parameters to your script so you'll need some filter...
Do you really find that dealing with numbers would be more handy than filenames?
 
Old 01-11-2019, 04:55 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 17,939

Rep: Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455
Not difficult using zenity's file selection dialog box. May not include all your desires but easy to add to a bash script.

https://linuxaria.com/howto/introduction-zenity-bash-gu
 
Old 01-11-2019, 05:45 PM   #5
GPGAgent
Member
 
Registered: Oct 2018
Posts: 109

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
what sort of list?

i think i'd use the shell's tab completion & wildcard functions to pass a list to the script as command line argument(s).

it seems very convoluted to do that inside the script; almost like coding a filemanager.
Wildcard is easy enough, but I can't wildcard the files I need to process. Thus my query. Thanks anyway
 
Old 01-11-2019, 05:48 PM   #6
GPGAgent
Member
 
Registered: Oct 2018
Posts: 109

Original Poster
Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by michaelk View Post
Not difficult using zenity's file selection dialog box. May not include all your desires but easy to add to a bash script.

https://linuxaria.com/howto/introduction-zenity-bash-gu
Yep, this looks a possible solution, I'll give it a go. Thanks
 
Old 01-11-2019, 05:55 PM   #7
GPGAgent
Member
 
Registered: Oct 2018
Posts: 109

Original Poster
Rep: Reputation: Disabled
Meanwhile I found this:

Code:
#!/bin/bash
cmd=(dialog --separate-output --checklist "Select options:" 22 76 16)
options=(1 "Option 1" off    # any option can be set to default to "on"
         2 "Option 2" off
         3 "Option 3" off
         4 "Option 4" off
        )
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
clear
for choice in $choices
do
    case $choice in
        1)
            echo "First Option"
            ;;
        2)
            echo "Second Option"
            ;;
        3)
            echo "Third Option"
            ;;
        4)
            echo "Fourth Option"
            ;;
    esac
done
So with a bit of bash I think I can replace the static code with generated code whichwill be my list of files. Then I can select the ones to process
 
Old 01-11-2019, 06:27 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 17,939

Rep: Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455
dialog and zenity are very similar. While dialog is based on ncurses, zenity is based on GTK+. whiptail is another tool to add dialog boxes to a bash script.
 
Old 01-13-2019, 11:01 AM   #9
GPGAgent
Member
 
Registered: Oct 2018
Posts: 109

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
dialog and zenity are very similar. While dialog is based on ncurses, zenity is based on GTK+. whiptail is another tool to add dialog boxes to a bash script.
I've had a look at all three, dialog, whiptail and zenity,

I like zenity, but which would you choose?

I'm looking to provide a file select list, could be 100+ files, could be only 10 files. I'd like to select a few for further processing, probably with ffmpeg.
 
Old 01-13-2019, 11:48 AM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 17,939

Rep: Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455
Whatever works best for you...
 
Old 01-13-2019, 11:50 AM   #11
GPGAgent
Member
 
Registered: Oct 2018
Posts: 109

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Whatever works best for you...
zenity it is then
 
Old 01-13-2019, 12:35 PM   #12
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,678

Rep: Reputation: 240Reputation: 240Reputation: 240
You might want to take a look at yad as well:

https://www.thelinuxrain.com/article...buttons-of-yad

https://smokey01.com/yad/

Like zenity it's GTK+ but zenity hasn't been in active development for some time. Yad picks up where zenity left off and is currently being actively developed.
 
1 members found this post helpful.
Old 01-15-2019, 10:44 AM   #13
GPGAgent
Member
 
Registered: Oct 2018
Posts: 109

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by kilgoretrout View Post
You might want to take a look at yad as well:

https://www.thelinuxrain.com/article...buttons-of-yad

https://smokey01.com/yad/

Like zenity it's GTK+ but zenity hasn't been in active development for some time. Yad picks up where zenity left off and is currently being actively developed.
Cheers, that looks good, works fine, but what does this message imply after I ran this test? I've attached the Yad dialog box which was fine.
Code:
 yad --text "Would you like to participate in a survey?"

** (yad:9230): WARNING **: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-QNvXiVQ3BO: Connection refused
Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.
Attached Thumbnails
Click image for larger version

Name:	YAD.png
Views:	4
Size:	8.0 KB
ID:	29473  
 
Old 01-15-2019, 01:33 PM   #14
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 10,429
Blog Entries: 7

Rep: Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592
both are just warnings.
especially gtk warnings, often even errors, are numerous and can ususally be ignored.
you can try
Code:
yad --text "Would you like to participate in a survey?" 2>/dev/null
to suppress them.
 
1 members found this post helpful.
Old 01-15-2019, 01:42 PM   #15
GPGAgent
Member
 
Registered: Oct 2018
Posts: 109

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
both are just warnings.
especially gtk warnings, often even errors, are numerous and can ususally be ignored.
you can try
Code:
yad --text "Would you like to participate in a survey?" 2>/dev/null
to suppress them.
I thought that would be the case, thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
'E:Malformed line 54 in source list /etc/apt/sources.list (dist parse), E:The list of vsssuccess@gmail.com Linux - Desktop 1 11-17-2010 09:17 AM
in copy files or ls files the command want to invert select some files how to?? hocheetiong Linux - Newbie 3 06-27-2008 07:32 AM
Bash script: how do I select second-to-last argument in a list Robert S Linux - Software 2 11-23-2007 04:06 PM
Command to select and move mutiple files from list in text file steve.paris Linux - Newbie 11 11-27-2005 01:44 PM
Select() did not select my socket thvo Programming 1 05-08-2005 01:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration