0

Thank you for your help! I have a command that can take more than a dozen arguments, but only requires two (input file name and output file name). The rest of the arguments are optional, but I often add two of them as they determine the quality of my output (i.e., samplerate, frequency). Each of these optional arguments has a limited number of options (i.e., samplerate=22050,32000,44100,4800) that I want to use, though I could enter arbitrary numbers, though that would be rare. Finally I have arguments that require no options, only that they either exist or not (debug yes or no). Currently, I invoke the past command and (using cursors) replace the previous arguments as needed.

Here is an example (I am not describing the exact command so you won't think I'm asking for "homework help" but I can describe it further if you wish)

command --input-file="somefoldercontainingfiles"/ --output-file="someotherfile.ext" --option-one 1 --option-two 2 --debug
  • My primary goal is to save time: fewer clicks is better, and it should obviously be faster than my current way of doing it.
  • My secondary goal is to reduce errors: using preset options and names is better.

I've seen a few scripts (like this one) that are a great start, but I'd still need to type the input file name, which can be as long as 60 characters.

  • Is there a way to get the script to recognize the working directory and list the file names and folders? Normally I'd invoke the script inside the directory I plan on using the app, so this would save time (kind of how bash already kind-of does this).

And as for the optional arguments (like samplerate), can I get the script to (1) ask WHETHER OR NOT to pass the argument and if "yes" to (2) present the argument with a default value (like 22050)?

tl;dr - I want to create a script that, when launched in the working directory, asks me for arguments for the command it will invoke. Some of those arguments are required, and it will help by identifying files so I don't make typos. Other arguments will be optional and it will ask whether to add them, and what their values will be.

Finally, I know enough bash script to be dangerous, but if you can recommend a resource to help me develop this on my own, I'd truly appreciate it. Thank you so much!

skaai
  • 101
  • yes and yes ... do you have any actual questions that are not a somewhat useless yes/no questions? – jsotola Sep 22 '21 at 02:17
  • Since you have a problem with typing long file names: are you aware of tab-completion? Also: your input file is actually a directory. Is that intentional? Does the command work on directories and expects several specific files in there? – FelixJN Sep 22 '21 at 05:51
  • 1
    select inputfile in *; do break; done ; echo "$inputfile" ? – pLumo Sep 22 '21 at 07:11
  • you can create an interactive script using read, but instead try and figure out how to write a bash-completion script: https://iridakos.com/programming/2018/03/01/bash-programmable-completion-tutorial – Ярослав Рахматуллин Sep 22 '21 at 20:34

0 Answers0