User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 391,563 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,676 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser:
Views: 6682 | Replies: 2
Reply
Join Date: Jul 2003
Location: Brazil
Posts: 13
Reputation: Reginald0 is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 0
Reginald0 Reginald0 is offline Offline
Newbie Poster

Pipe inside variable isn't working in bash

  #1  
Jan 30th, 2004
Hi, folks!

See the examples:

bash$ X="ls"; $X
file1 file2 file3
*** Works correctly!

bash$ X="ls | wc"; $X
ls: |: No such file or directory
ls: wc: No such file or directory
*** Doesn't work!

How to make the last command work correctly as first?

Thanks in advance!

Reginald0
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2004
Posts: 1
Reputation: juppe10a is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
juppe10a juppe10a is offline Offline
Newbie Poster

Re: Pipe inside variable isn't working in bash

  #2  
Jan 30th, 2004
Hi,

if you want to store command result in variable use back quote:
# X=`ls | wc`
# echo $X.

or use command alias:
# alias X="ls | wc"
# X
Reply With Quote  
Join Date: Jul 2003
Location: Brazil
Posts: 13
Reputation: Reginald0 is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 0
Reginald0 Reginald0 is offline Offline
Newbie Poster

Re: Pipe inside variable isn't working in bash

  #3  
Jan 30th, 2004
juppe10a,

It's not exactly what I was looking for, cause the command result isn't important to store to a variable, but the command execution itself.
I found a perfect way to do that:

# X="ls | wc"; eval $X

Simple but functional.

Thanks anyway!

Reginald0
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Shell Scripting Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 10:05 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC