I'm paranoid about this, but hopefully it's a simple question:

Is there any difference between

cat file1 | egrep -oP "[Mm]y string" > /home/user/file.txt


cat file1|egrep -oP "[Mm]y string">/home/user/file.txt

i.e., does it matter if I have spaces padding the pipe (|) and redirection (>) characters? I'm really paranoid that having spaces there the spaces will somehow end up in the output file when I don't want that. Can anyone clarify? (Using Ubuntu 12/bash if that matters.)

  • 1
    The only differences are a) cosmetic and b) convenience when editing command lines in bash - e.g. a "word" is delimited by spaces, so without spaces around | or > then typing Ctrl-W to delete the previous "word" would delete more than you probably wanted. ditto for cursor-movement keystrokes like Esc-f and Esc-b etc.
    – cas
    Sep 17, 2012 at 5:37

1 Answer 1


In the shell command line, unquoted spaces only serve to delimit words during command parsing. They are not passed on, neither in the arguments the command sees nor in the standard input stream.

  • Are you sure there isn't a security vulnerability with using a space after the operators? I am having a hard time reproducing it now, but there is a common exploit where a malicious user can change the intended operation by using a file like " fileName" when the intended file was "fileName". Nov 21, 2019 at 15:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .