0

I have a question about shell code

some_fun(){
cat - 1>& 2 << EOF
hello word 
EOF
}

What does the "-" after cat do?

ahdr
  • 19
  • 5
  • 2
    Like most Unix commands, `-` as an input filename means to read standard input. – Barmar Feb 11 '22 at 02:47
  • 1
    There's no need for it here, since `cat` reads standard input by default if there are no filename arguments. – Barmar Feb 11 '22 at 02:48
  • It's useful if you want to mix standard input with other files, e.g. `cat file1 - file2` will put standard input between the two files. – Barmar Feb 11 '22 at 02:48
  • There must be previous questions like this, but I can't figure out a search term to find it. Hopefully someone else can, so this can be closed as a duplicate. – Barmar Feb 11 '22 at 02:52
  • 1
    @Barmar "what does hyphen mean in unix?" -> https://stackoverflow.com/questions/8045479/whats-the-magic-of-a-dash-in-command-line-parameters Clear duplicate. – dan Feb 11 '22 at 04:10
  • 1
    @ahdr you can learn a lot by typing man commandname. For example, typing man cat gave me this information "If file is a single dash (`-') or absent, cat reads from the standard input." – SydOwl Feb 11 '22 at 06:18
  • Thank you very much for your answer – ahdr Feb 11 '22 at 06:25

0 Answers0