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.

Required fields*

13
  • Date | sh - wouldn’t work. echo date | sh - would though. Ok, so now we know what - does. It’s actually unnecessary. Can you do the same with xargs. I’m on a mac, so it’s BSD version of xargs. I tried echo date | xargs, but it didn’t work. Commented Feb 12, 2018 at 3:55
  • Even on the Mac, echo date|xargs should print the word date to stdout. Of course in this case, you could simply write echo date, but redundantly piping it to xargs still should not cause any problem. What error message do you get? Commented Feb 12, 2018 at 7:28
  • I was trying to execute date. I could write “ echo date | xargs xargs, but that doesn’t work in the mac version of xargs. So eval doesn’t accept piped input, source has a bug in bash 3.2 (mac version) and you can’t do xargs xargs on the mac. This leaves us with using a while loop “while read line; do $line; done” Commented Feb 12, 2018 at 13:56
  • The dash/hyphen is a standard option (or whatever it should be called) for POSIX sh (link). The way to force the shell to read from stdin is -s, e.g. echo 'echo "args: $*"' | bash -s - foo bar prints args: foo bar. Commented Aug 17, 2018 at 8:54
  • 1
    @sofs1 It means that a (first only) - is equivalent to a (first only) --. Any further - or -- are treated as normal arguments not having special meaning. Well, actually, naming files for the shell. Commented Aug 10, 2019 at 19:40