Results 1 to 6 of 6
Hi guys, I'm trying to get to grips with pipe.
Often I want to look at the python code behind one of my custom scripts in the terminal. Usually I ...
- 02-06-2012 #1Just Joined!
- Join Date
- Feb 2012
- Posts
- 3
Piping problems
Hi guys, I'm trying to get to grips with pipe.
Often I want to look at the python code behind one of my custom scripts in the terminal. Usually I type "which myCommand", select the full path given, and use "cat".
From what I've read, a pipe "|" passes the output of the left hand side to the input of the right. So why doesn't this work?
Thanks!Code:which myCommand | cat
Harry
- 02-06-2012 #2
Because the pipe connects to stdin, but in this case you need to pass the path/filename as an argument.
Try this
Code:which myCommand |xargs -l1 cat
You must always face the curtain with a bow.
- 02-07-2012 #3
Although Irithori's command does work (xargs takes stdin and uses it as commandline arguments), it is not the best way to achieve what you want.
You want to replace a part of a commandline with the output of another command. The standard way of doing this is:
Code:cat $(which myCommand)
DISTRO=Arch
Registered Linux User #388732
- 02-07-2012 #4Just Joined!
- Join Date
- Feb 2012
- Posts
- 3
Hi guys, thanks for your answers.
The xargs way works fine. However, when I use
I get a "Illegal variable name." I did hit on some success with this:Code:cat $(which myCommand)
Code:cat `which myCommand`
- 02-07-2012 #5
The $() construct works in bash.
And I agree with Cabhan, that it is nicer to read.
Which shell do you use?You must always face the curtain with a bow.
- 02-07-2012 #6Just Joined!
- Join Date
- Feb 2012
- Posts
- 3
That would explain it; I'm using tcsh.


Reply With Quote