Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
09-12-2008, 12:44 AM
|
#1
|
|
Member
Registered: Feb 2007
Posts: 382
Rep:
|
help with execute mulitple shell script within shell script
I am trying to get a result of one executable to be input of other executable. I found one on the internet, and it works great.
However, when put it in the shell script, it does not work..
Can someone help
here is the command.
$ sox infile outfile vol `sox infile -n stat -v 2>&1`
In my shell script, i wrote
cm=`sox infile outfile vol `sox infile -n stat -v 2>&1``
also try
cm=`sox infile outfile vol $(sox infile -n stat -v 2>&1)`
None of this work. can someone help?
|
|
|
|
09-12-2008, 01:04 AM
|
#2
|
|
Senior Member
Registered: Jun 2008
Posts: 2,529
Rep:
|
What you doing is placing the output of the second sox command onto the command line of the first sox command. This isn't what you want, and won't work.
Under the Filenames section of the man page, sox shows filenames can be:
Quote:
-
SoX can be used in pipeline operations by using the special filename `-' which, if used in place of an input filename, will cause SoX will read audio data from `standard input' (stdin), and which, if used in place of the output filename, will cause SoX will send audio data to `standard output' (stdout). Note that when using this option, the file-type (see -t below) must also be given.
|
So, you want to use a dash as the file name, and a pipe.
Code:
sox infile - vol | sox - -n stat -v
But you must use the -t option to specify the file type as indicate above. Add -t as appropriate. I've not used sox, so can't advise what to specify with -t.
Last edited by Mr. C.; 09-12-2008 at 01:05 AM.
|
|
|
|
09-12-2008, 01:12 AM
|
#3
|
|
Member
Registered: Jun 2008
Location: Toronto, Canada
Distribution: Mandriva, RHEL
Posts: 122
Rep:
|
You could deivide your line into two:
Code:
vol=`sox infile -n stat -v 2>&1`
cm=`sox infile outfile vol $vol`
|
|
|
|
09-12-2008, 01:20 AM
|
#4
|
|
Senior Member
Registered: Jun 2008
Posts: 2,529
Rep:
|
Vit77's response makes me think I may have misinterpreted the request.
If the OP is trying to perform nested command substitution, that works just fine:
Code:
$ set -v
$ echo $(echo $(echo It Works))
echo $(echo $(echo It Works))
echo $(echo It Works)
echo It Works
It Works
My response was thinking the OP was trying to perform two different sox operations on a file, sending the output of one sox operation over a pipe to the second sox operation.
Perhaps the OP can be more specific than "None of this work".
Last edited by Mr. C.; 09-12-2008 at 01:23 AM.
|
|
|
|
09-12-2008, 02:30 AM
|
#5
|
|
Member
Registered: Jun 2008
Location: Toronto, Canada
Distribution: Mandriva, RHEL
Posts: 122
Rep:
|
ufmale said that the first way (commant-line) works great.
The first sox calculates and returns the maximum volume of an audio file, and this value is substituted as an argument the first sox.
I suspect the main fail reason of the last OP's script might be in -v 2>&1 structure.
-v option requires an argument, so 2 should be this argument, whereas 2> could be interpreted as stderr.
If so, the decision is a space char between 2 and >.
|
|
|
|
09-12-2008, 10:57 AM
|
#6
|
|
Senior Member
Registered: Jun 2008
Posts: 2,529
Rep:
|
The 2>&1 is redirecting STDERR to the STDIN stream. The shell parses this as a single unit. If 2 were an option value to -v, that would leave >&1. This would be equivalent to >1 2>&1, which isn't likely desired.
The first form posted:
Code:
cm=`sox infile outfile vol `sox infile -n stat -v 2>&1``
will never work because the OP is not noticing / understanding that nested quotes won't work without escaping the inner quotes. The second backquote immediately terminates the first back quote. The same for backquotes number 3 and 4, which results in at attempt to assign three components to cm:
cm= `sox infile outfile vol ` sox infile -n stat -v 2>&1``
and this is equivalent to:
Code:
$ cm=a b c
bash: b: command not found
The second form works correctly, because there is no nesting of quotes. Using set -x, we can see this (I used print "retval" to be a phony return value from the first sox):
Code:
$ set -x
$ cm=`echo sox infile outfile vol $(printf "retval" sox infile -n stat -v 2>&1)`
llline 1: printf retval sox infile -n stat -v
lline 1: echo sox infile outfile vol retval
line 14: cm='sox infile outfile vol retval'
What the OP needs to show is the exact input/output that shows the problem encountered, and not do the interpretation for us.
Last edited by Mr. C.; 09-12-2008 at 10:58 AM.
|
|
|
|
09-13-2008, 12:21 AM
|
#7
|
|
Member
Registered: Feb 2007
Posts: 382
Original Poster
Rep:
|
Thank you Mr. C. and Vit77. Now I am understanding more about nesting issue.
It now work great using the suggestion from Vit77.
Quote:
vol=`sox infile -n stat -v 2>&1`
cm=`sox infile outfile vol $vol`
|
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 02:42 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|