Visit The New, Modern Unix Linux Community

Process Substitution Question?

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Process Substitution Question?
# 1  
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:

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:

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:

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


however, echo yields a different result:
echo <(basename /apps/out/report.html)


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?

# 2  
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.
# 3  
I see - Ok - that makes perfect sense Smilie

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  
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.
# 5  
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.

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

This User Gave Thanks to Corona688 For This Post:
# 6  
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 ----------

Originally Posted by Corona688
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.

( 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!

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #173
Difficulty: Easy
The key difference between Linux and many other popular modern operating systems is that the Linux kernel and other components are free and open-source software.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with process substitution

i have tried process substitution, but run in some problems. this works: samtools view -h $SAMdir/$b.bam | htseq-count -m union -s no -q -t exon -i gene_id - $gtf > $b.count & but this not: htseq-count -m union -s no -q -t exon -i gene_id <(samtools view -h $SAMdir/$b.bam) $gtf >... (7 Replies)
Discussion started by: dietmar13
7 Replies

2. Shell Programming and Scripting

Cannot make pipe for process substitution: Too many open files

Hi, I've came across an issue with a script I've been writing to check DHCP addresses on an Solaris system, the script has been running reasonably well, until it hit the following problem: ./sub_mon_v2: redirection error: cannot duplicate fd: Too many open files ./sub_mon_v2: cannot make... (3 Replies)
Discussion started by: CiCa
3 Replies

3. AIX

AIOServer process question

Hi I've been trying to learn a bit more about AIOServer processes and how my company administers them, one question i have is, while checking, most of my servers show a memory overhead of about 448 k per aioserver process (nmon -A) however i have found a few with figures of 67 or 56k. Most... (0 Replies)
Discussion started by: philib
0 Replies

4. UNIX for Dummies Questions & Answers

Zombie process question

Hey guys, So i did some research on the site but previous posts answered most of my questions about zombie processes but I have one question that didnt seem to get addressed "how do you find the parent or parent ID of a zombie process so you can kill it?" I know p -kill doesnt always just... (6 Replies)
Discussion started by: kingpin007
6 Replies

5. Shell Programming and Scripting

sed substitution question

Hi I am trying to modify the file using "sed" editor and the command fails due to the fact that the variable I use contains "/" (slashes). Here is the example: v=1 back_dir="/ts/data" $ sed "s/\/t${v}\/data/${back_dir}/" /tmp/f323odb.lrl.alt sed: command garbled: s/\/t1\/data//ts/data/ ... (2 Replies)
Discussion started by: aoussenko
2 Replies

6. Shell Programming and Scripting

Process substitution

Just playing around with process substitution. Hoping maybe someone can give me some help on what I'm doing wrong. When this script is run, "Null message body; hope that's ok" is returned and the script hangs. I can't seem to work out what I'm doing wrong. Here is the script: #!/bin/bash... (3 Replies)
Discussion started by: mandelbrot333
3 Replies

7. Shell Programming and Scripting

Can process substitution be used as an input file to another program?

Hey, I was trying to figure out how to launch a program from the command line, and it works if you pass it a config file. I was thinking about writing a script to dynamically create the config file and pass it to the command using something like command substitution (so I don't actually have to... (3 Replies)
Discussion started by: bj0
3 Replies

8. Shell Programming and Scripting

Difference between "Command substitution" and "Process substitution"

Hi, What is the actual difference between these two? Why the following code works for process substitution and fails for command substitution? while IFS= read -r line; do echo $line; done < <(cat file)executes successfully and display the contents of the file But, while IFS='\n' read -r... (3 Replies)
Discussion started by: royalibrahim
3 Replies

9. Shell Programming and Scripting

String Substitution Question

When I run the script I pass in 2 expressions (ex. replace.ksh new old) I want the script to go line by line for a given file in a given directory and replace the word new with old. Of course in my line where I have the awk statement it is replacing the 2nd word with 1st instead of new with... (3 Replies)
Discussion started by: goodrics
3 Replies

10. UNIX for Dummies Questions & Answers

bad substitution problem (easy question)

hi, what i want to do is to convert all the txt file under my directory to the properties file using the native2ascii command. however, when i run my script, i got bad substitution error. what's wrong with my script ? pls help. thanks #!/bin/sh curDIR=`pwd` oldExt='txt'... (10 Replies)
Discussion started by: champion
10 Replies

Featured Tech Videos