Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • Found the answer. Something like: echo "Test" | xargs bash getoptscript.sh -m . But is this "good" way? Commented Jun 28, 2017 at 12:36
  • So, you want the script to read stdin if the argument to the switch is a dash - and otherwise use the argument itself? That should be a simple test within the m) case, read from stdin if OPTARG is -, otherwise use OPTARG itself. I'm not exactly sure if this is what you wanted, though. It would seem more common to have dash as a filename representing stdin. Some commands have a different option characters for giving the literal value and for giving a reference to a file from which to read it Commented Jun 28, 2017 at 12:40