LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-28-2020, 11:09 AM   #1
narcissus256
LQ Newbie
 
Registered: Aug 2020
Distribution: Arch
Posts: 9

Rep: Reputation: Disabled
Bash: script with getopts and file globbing?


Hi,

I am trying to write a script where I need to get an input from a user from getopts.
That wouldn't be a problem, but I also need the user to select any number of files which the script should process.
Let's say that a command should look like this:

Code:
mp3tag -a "Artist name" -t "Song title" -n "Track number" *.mp3
How can I ensure that my mp3tag script understands file globbing? I have been scripting for a while, but can't get over this obstacle. Thank you!
 
Old 11-28-2020, 11:19 AM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Shell itself understands globbing. Just shift each processed parameter.
Quote:
When the end of options is encountered, getopts exits with a return value greater than zero. OPTIND is set to the index of the first non-option argument, and name is set to ‘?’.
 
Old 11-28-2020, 11:25 AM   #3
narcissus256
LQ Newbie
 
Registered: Aug 2020
Distribution: Arch
Posts: 9

Original Poster
Rep: Reputation: Disabled
Yes, shifting parameters is surely a possibility. But what if a user decides to just specify the "Song title"? The parameters would be shifted too far, into the actual filenames.
 
Old 11-28-2020, 11:34 AM   #4
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
See examples in BashFAQ.
Edit. Wrong link.

Last edited by shruggy; 11-28-2020 at 11:44 AM.
 
Old 11-28-2020, 01:31 PM   #5
narcissus256
LQ Newbie
 
Registered: Aug 2020
Distribution: Arch
Posts: 9

Original Poster
Rep: Reputation: Disabled
Great, thank you!
 
  


Reply

Tags
bash, getopts



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
getopts question in bash script. lleb Linux - Newbie 4 07-20-2012 05:37 PM
[SOLVED] passing globbing expressions as argument to bash script mdcjsps Linux - Newbie 6 10-29-2011 05:09 AM
[SOLVED] bash : getopts problem in bash script. angel115 Programming 2 03-02-2009 10:53 AM
LXer: Bash Extended Globbing LXer Syndicated Linux News 0 10-09-2008 11:10 AM
Globbing Problem in BASH Hink Programming 2 07-28-2005 12:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:58 AM.

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
Open Source Consulting | Domain Registration