LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-06-2013, 04:09 PM   #1
etech3
Senior Member
 
Registered: Jul 2009
Location: Virginia
Distribution: Debian Stable Testing Sid Slackware CentOS
Posts: 1,055
Blog Entries: 2

Rep: Reputation: 45
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
 
Old 08-06-2013, 04:40 PM   #2
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by etech3 View Post
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
 
Old 08-06-2013, 11:13 PM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
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.

Last edited by konsolebox; 08-06-2013 at 11:14 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to read the updated buffer in kernel space from user space raju_1234 Linux - Embedded & Single-board computer 0 06-20-2012 01:50 AM
Division of Logical Memory Space in to User Space and Kernel Space shreshtha Linux - Newbie 2 01-14-2010 09:59 AM
Do we have any chance of calling user space callback function from kernel space? ravishankar.g Linux - Newbie 1 09-22-2009 07:14 PM
how to call socket prog code written in user space from kernel space???HELP kurt2 Programming 2 07-15-2009 09:56 PM
LXer: Worms in space: NASA confirms International Space Station infected LXer Syndicated Linux News 0 08-28-2008 09:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration