Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-04-2012
Registered User
 
Join Date: May 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Process Substitution Question?

Hello to all. I'm new to this forum, so please go easy on me. =)

I am working on a script to send two e-mail attachments in a single e-mail, and am running into a little bit of an issue when using process substitution. I am using the following:


Code:
cat <(uuencode $1 <(basename $1)) <(uuencode $2 <(basename $2)) | mailx -s $3 $4

Basically, I am attempting to encode the attachments with a command functionally similar to:


Code:
uuencode /apps/out/report.html report.html

uuencode has 2 parameters, one is the input file, and the other is the output file name. I basically want the user to see the attachment with the name report.html instead of /apps/out/report.html

For this task, I am using basename, which outputs just the filename, but, when I use it in process substitution with uuencode, what I get is /dev/fd/63 instead of the expected report.html "

I don't think the problem is uuencode, because I can use the following commands and get the following results:


Code:
cat <(basename /apps/out/report.html)

output:
Code:
report.html

however, echo yields a different result:

Code:
echo <(basename /apps/out/report.html)

output:
Code:
/dev/fd/63

I guess I don't understand why echo is getting a different parameter than cat.. Can someone shed some light on why this is, and perhaps suggest how I might get around it?

Thanks!
Sponsored Links
    #2  
Old 05-04-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,371
Thanks: 490
Thanked 2,534 Times in 2,417 Posts
What does echo filename do? It prints the string 'filename'.

What does cat filename do? It reads from the file named filename.

So the 'echo' just prints the path to the pipe it ought to be reading from. cat actually reads from the pipe, and shows the output of the program.
Sponsored Links
    #3  
Old 05-04-2012
Registered User
 
Join Date: May 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
I see - Ok - that makes perfect sense

I now understand why the output is what it is. Now I just need to know if there's a way I can work around it. For the sake of simplicity, how could I make echo display the results of the basename command?
    #4  
Old 05-04-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,371
Thanks: 490
Thanked 2,534 Times in 2,417 Posts
You don't need echo to do so. basename is fully capable of doing so all by itself. All you're doing with all this redirection is changing where it ends up.
Sponsored Links
    #5  
Old 05-04-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,371
Thanks: 490
Thanked 2,534 Times in 2,417 Posts
I get it now. You want backticks. And also, a subshell, to combine their results into one pipe -- you can group processes together with ( ), and separate them with ; inside.


Code:
( uuencode $1 `basename $1` ; uuencode $2 `basename $2` ) | mailx -s $3 $4

The Following User Says Thank You to Corona688 For This Useful Post:
rommager (05-04-2012)
Sponsored Links
    #6  
Old 05-04-2012
Registered User
 
Join Date: May 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Take it to the next example:

uuencode /apps/out/report.html basename /apps/out/report.html

This doesn't work because uuencode reads basename as its second parameter, and /apps/out/report.html as a third parameter.

Now of course I'm not using "/apps/out/report.html", my script is using $1.

---------- Post updated at 05:53 PM ---------- Previous update was at 05:50 PM ----------

Quote:
Originally Posted by Corona688 View Post
I get it now. You want backticks. And also, a subshell, to combine their results into one pipe -- you can group processes together with ( ), and separate them with ; inside.


Code:
( uuencode $1 `basename $1` ; uuencode $2 `basename $2` ) | mailx -s $3 $4

Aha! That's it! I have now learned about backticks! That works!

Thanks Corona!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed substitution question aoussenko Shell Programming and Scripting 2 09-21-2010 11:01 AM
Process substitution mandelbrot333 Shell Programming and Scripting 3 03-01-2010 08:33 PM
Can process substitution be used as an input file to another program? bj0 Shell Programming and Scripting 3 06-24-2009 01:06 AM
Difference between "Command substitution" and "Process substitution" royalibrahim Shell Programming and Scripting 3 12-15-2008 10:20 AM
String Substitution Question goodrics Shell Programming and Scripting 3 07-24-2003 04:00 PM



All times are GMT -4. The time now is 01:11 AM.