Bash - read as a fallback to $@

Posted by user137369 on Super User See other posts from Super User or by user137369
Published on 2012-06-09T01:08:19Z Indexed on 2012/06/09 4:42 UTC
Read the original article Hit count: 541

Filed under:
|
|

I have a working bash script (working on OSX) that takes files and directories as input and does something like

for inputFile in $@
do
[someStuff]
done

but I want to provide a “fallback”, meaning, if the script is started with no arguments (double-clicked, for example), it can take input at that time, by letting the user drop the files directly on the terminal (possibly through read but not mandatory, I'm open to better/different solutions).

I'm guessing I should use some kind of if statement, but I'm not sure how. I'd like to not have to essentially duplicate the script's size by two by repeating [someStuff] for each case.

Thank you.

© Super User or respective owner

Related posts about osx

Related posts about bash