- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell variable containing pipe
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 07:41 AM
09-18-2003 07:41 AM
Can someone explain why a remote shell interprets a pipe, but a local shell doesn't?
e.g.
# COMMAND='echo hello | grep hell'
# remsh other_host $COMMAND
hello
# $COMMAND
hello | grep hell
Why does the local shell execute the echo, but not react to the pipe?
What syntax should I use to get the same result as the remsh?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 07:48 AM
09-18-2003 07:48 AM
Re: Shell variable containing pipe
You did the remote command;
echo hello | grep hell
and hell is part of hello so it echoed back hello. This is normal behaviour.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 07:57 AM
09-18-2003 07:57 AM
Re: Shell variable containing pipe
Use:
#COMMAND=`echo hello|grep hell`
#echo $COMMAND
Regards,STAN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 07:58 AM
09-18-2003 07:58 AM
Re: Shell variable containing pipe
On your local host, the echo command only regurgitates what you give it in quotes, it will not treat it as an executable command... merely as plain text.
You would have to pass the variable to a script or one-liner... or change the quotes to back tics... as below.
You will need to change it to back tics..the one next to the 1 key....
# COMMAND=`echo hello | grep hello`
# echo $COMMAND
hello
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 08:03 AM
09-18-2003 08:03 AM
Re: Shell variable containing pipe
of course zero for this post of course!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 08:06 AM
09-18-2003 08:06 AM
Re: Shell variable containing pipe
Really your answer is more complete
and usefull.
Regards,Stan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 08:37 AM
09-18-2003 08:37 AM
SolutionOn the local system
$COMMAND
is replaced with the the contents of COMMAND and the echo command is executed. But the "|" has no meaning except on the command line you typed. It is not processed by the shell.
If you wanted $COMMAND to recognize the "|", then use the "eval" shell command (see man sh-posix).
eval $COMMAND
Then the shell will rescan the command line a second time, see the "|" and do the pipe operation.
The reason it works on the remsh is the same situation. When $COMMAND is run on the remote host, the remote host shell rescans the command line and sees the "|" as its special meaning.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 09:26 AM
09-18-2003 09:26 AM
Re: Shell variable containing pipe
Using "eval" is preferable to using "echo $(command)" or backquotes because it retains the formatting, e.g.
# COMMAND1="/usr/sbin/lanscan |cut -c1-8,24-80"
# COMMAND2=$(/usr/sbin/lanscan |cut -c1-8,24-80)
# echo $COMMAND2
Hardware Crd Hdw Net-Interface NM MAC HP-DLPI DLPI Path In# State NamePPA ID Type Support Mjr# 0/0/0/0 0 UP lan0 snap0 1 ETHER Yes 119 0/4/0/0 1 UP lan1 snap1 2 ETHER Yes 119 0/6/0/0 2 UP lan2 snap2 3 ETHER Yes 119 0/2/0/0 0 UP ixe1 5 X25 No 77 0/2/0/0 0 UP ixe2 6 X25 No 77
# eval $COMMAND1
Hardware Crd Hdw Net-Interface NM MAC HP-DLPI DLPI
Path In# State NamePPA ID Type Support Mjr#
0/0/0/0 0 UP lan0 snap0 1 ETHER Yes 119
0/4/0/0 1 UP lan1 snap1 2 ETHER Yes 119
0/6/0/0 2 UP lan2 snap2 3 ETHER Yes 119
0/2/0/0 0 UP ixe1 5 X25 No 77
0/2/0/0 0 UP ixe2 6 X25 No 77
# remsh other_host $COMMAND1
Hardware Crd Hdw Net-Interface NM MAC HP-DLPI DLPI
Path In# State NamePPA ID Type Support Mjr#
0/0/0/0 0 UP lan0 snap0 1 ETHER Yes 119
0/5/0/0 2 UP lan2 snap2 2 ETHER Yes 119
0/10/0/0 1 UP lan1 snap1 3 ETHER Yes 119
0/8/0/0 0 UP ixe1 5 X25 No 79
0/8/0/0 0 UP ixe2 6 X25 No 7