0

If reading this I then understanding, that you can set the stdin to be piped to the command as parameter to a placeholder "-"

like:

cat <<EOF | printf -  
hello  
new line
EOF

But it only prints "%"?

Chris G.
  • 157
  • 5
  • `printf` doesn't read from stdin. This smells like an XY problem: what are you really trying to accomplish? – glenn jackman Sep 30 '21 at 19:59
  • To understand “-“ – Chris G. Sep 30 '21 at 20:01
  • 1
    The hyphen meaning is specific to each command that implements it, but generally, yes, it is a placeholder for "read stdin as a file". `printf` does not implement it. But `diff` does. So does `grep`. – glenn jackman Sep 30 '21 at 20:40
  • Even commands that interpret `-` as a placeholder for stdin only do so if it occurs where they expect an input filename to be (and generally interpret it as stdout if it's where an output filename should be). The first argument to `printf` is a format string, not a filename, so interpreting it as stdin doesn't make any sense. – Gordon Davisson Oct 01 '21 at 19:36
  • I guess “/dev/fd/1” would be the same for any command supporting “-“ or file input. – Chris G. Oct 01 '21 at 19:59

0 Answers0