Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

60%
+1 −0
Q&A For scripting what are the pros and cons of command line arguments versus capturing input at the start?

I largely agree with existing answers, but wanted to add this: In many cases, there is no clear answer one way or the other. Take the program wc which counts characters and lines. Should the inter...

posted 10mo ago by matthewsnyder‭

Answer
#1: Initial revision by user avatar matthewsnyder‭ · 2023-06-23T20:11:01Z (10 months ago)
I largely agree with existing answers, but wanted to add this:

In many cases, there is no clear answer one way or the other. Take the program `wc` which counts characters and lines. Should the interface be `wc file.txt` or `cat file.txt | wc`? Compelling arguments can be made for the value of either. Yet we have to pick one.

Actually we don't. `wc` supports both. More complex programs support the well known `-` parameter, so `cat file.txt | some_program --file -` as a way of making it a bit more coherent.

Interactive input falls under this as well. `ssh-keygen` will interactively ask for the key type. But with `ssh-keygen -t ed25519` it will not ask.

CLI arguments, standard input (from pipe) and interactive input form the three pillars of Unix-style human-computer interaction. All programs should aspire to provide first-class support for all three *eventually*, even if they won't, just like "all kids" aspire to be astronauts. Imagine a stool with two legs. You can make it work, and it's certainly better than a stool with one leg, and way better than none, but once you get to three legs it gets really good.

Of course you have to start somewhere. For your first leg, just pick one. Whatever you feel is **a** likely use case for your script, and let users rely on Unix to "improvise" the missing legs:

* `cat` if they want to use args but you support stdin
* Shell redirection if they want stdin but you want args
* `expect` if you support interactive but they want scriptable

As your program matures, you can use the experience gained from maintaining it to decide which next method of input you should add support for.