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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
09-12-2008, 01:44 AM
|
#1
|
Member
Registered: Feb 2007
Posts: 386
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, 02: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 02:05 AM.
|
|
|
09-12-2008, 02:12 AM
|
#3
|
Member
Registered: Jun 2008
Location: Toronto, Canada
Distribution: SuSE, RHEL, Mageia
Posts: 132
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, 02: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 02:23 AM.
|
|
|
09-12-2008, 03:30 AM
|
#5
|
Member
Registered: Jun 2008
Location: Toronto, Canada
Distribution: SuSE, RHEL, Mageia
Posts: 132
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, 11: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 11:58 AM.
|
|
|
09-13-2008, 01:21 AM
|
#7
|
Member
Registered: Feb 2007
Posts: 386
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`
|
|
|
|
All times are GMT -5. The time now is 01:32 PM.
|
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
|
|