LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   to space or not to space when using pipe (https://www.linuxquestions.org/questions/programming-9/to-space-or-not-to-space-when-using-pipe-4175472377/)

etech3 08-06-2013 04:09 PM

to space or not to space when using pipe
 
Using bash 4.2 in Debian 7.1 Wheezy. But this is a question of bash in general.

When using pipe (|) should there be a space before and after the pipe?

When searching for scripts on the net, I come across a lot of scripts that have a space after the pipe.

As a general good habit, I try to always not have a space after the pipe.

So the question as Shakespeare would say: to space or not to space when using pipe. That is the questtion.

Thanks

Doc CPU 08-06-2013 04:40 PM

Hi there,

Quote:

Originally Posted by etech3 (Post 5004290)
Using bash 4.2 in Debian 7.1 Wheezy. But this is a question of bash in general.

When using pipe (|) should there be a space before and after the pipe?

When searching for scripts on the net, I come across a lot of scripts that have a space after the pipe.

As a general good habit, I try to always not have a space after the pipe.

So the question as Shakespeare would say: to space or not to space when using pipe. That is the questtion.

there's a very short answer: It doesn't matter.
Just use spaces if you like, or don't use them if you like that. Whatever pleases your eye.
From a technical point of view, there's no difference.

I prefer to use a space before and after the pipe character for the sake of clarity.

[X] Doc CPU

konsolebox 08-06-2013 11:13 PM

If the space worries you that it might be an argument, it won't. As an example:
Code:

echo -n abc | ( cat; echo xyz; )
Won't show "abc xyz" but "abcxyz". Spaces in the open are just argument separators.

Also,
Code:

echo a b c
Sends "a", "b", and "c" separately as three (3) arguments to echo, not "a b c" as a single line. But echo appends those strings in the output with space as separator thereby showing "a b c". If you try separating those arguments with two or more spaces, or with tabs you would still have "a b c" as an output.


All times are GMT -5. The time now is 01:33 AM.