How can I use a pipe operator in a variable: OPTION="| command"?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can I use a pipe operator in a variable: OPTION="| command"?
# 1  
Old 05-25-2009
How can I use a pipe operator in a variable: OPTION="| command"?

I have a string of commands I am piping some data through and I want to allow command line switches to select which commands are used. I want to do something like this:
Code:
OPTION="| command3"
command1 -a -b c.txt | command2 -d -e $OPTION >result.txt

I want to do it that way because OPTION may be blank, or may be multiple commands. But it doesn't work.

Is there any way I can make it work?
# 2  
Old 05-25-2009
you can use eval

Code:
OPTION="| command3"
FINALCOMMAND="command1 -a -b c.txt | command2 -d -e $OPTION"

eval $FINALCOMMAND >result.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

2. Solaris

Netra X1 LOM: Unable to change any variable via the "set" command

I'm posting here as it didn't seem quite right in the hardware section (as it's LOM commands). My apologies if I have that wrong though :) I've finally gotten round to configuring the LOM on my Netra X1, but I can't get it to change the hostname via the "set" command: lom>show hostname... (2 Replies)
Discussion started by: Smiling Dragon
2 Replies

3. UNIX for Dummies Questions & Answers

What is the meaning of "-s" option in "if" statement?

Hi Guys, I'm sorry but I can't find answer for this, what is the meaning of -s option in "if" statement on unix scipting. Please see sample below: opath=/home/output for i in N1 N2 N3 N4 do echo $i if then grep $i $opath/N5_CRAI > $opath/N5_$i.crai chmod 777 $opath/N5_$i.crai ... (7 Replies)
Discussion started by: rymnd_12345
7 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

What "-a" operator means in "if" statement

Hi I am trying to figure out what the following line does, I work in ksh88: ] && LIST="$big $LIST" Not sure what "-a" means in that case. Thanks a lot for any advice -A (1 Reply)
Discussion started by: aoussenko
1 Replies

6. Shell Programming and Scripting

"From" option in mail command

hi, Please suggest me how to mention "from" option in mailx command? mailx -s "Info " ssa@org.com < file (2 Replies)
Discussion started by: sreelu
2 Replies

7. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

8. Shell Programming and Scripting

sub option of awk command not working with "\" character.

Hi all, I would like to replace some string in a text file by some string which would contains special characters like "/","\". I.e. I have a text file with the statement contactperson somewhere in it. Now I want to replace it by something else which includes special characters like "/","\" ... (1 Reply)
Discussion started by: shareef
1 Replies

9. UNIX for Dummies Questions & Answers

How to pass option with "at" command?

Hi, I've got a ksh script that expects a file name as a parameter. The script in turn executes another command "sas", after assigning some environment variables, passing that file name down the line. From the command prompt, all works swell if I type "sasbatch filename". However, if I try... (3 Replies)
Discussion started by: bd9439
3 Replies

10. Shell Programming and Scripting

bash: "undefined variable" and pipe

Hi, haven't found anything about this through searching, so may be a new topic: when doing this: set -o nounset set -o errexit find . -name "*.lib" | while read library; do echo ${libary} done echo "after while" I expect the script to exit within the while loop (because of nounset and... (6 Replies)
Discussion started by: nagaidhlig
6 Replies
Login or Register to Ask a Question