LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   help with execute mulitple shell script within shell script (http://www.linuxquestions.org/questions/programming-9/help-with-execute-mulitple-shell-script-within-shell-script-669391/)

ufmale 09-12-2008 12:44 AM

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?

Mr. C. 09-12-2008 01:04 AM

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.

Vit77 09-12-2008 01:12 AM

You could deivide your line into two:

Code:

vol=`sox infile -n stat -v 2>&1`
cm=`sox infile outfile vol $vol`


Mr. C. 09-12-2008 01:20 AM

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".

Vit77 09-12-2008 02:30 AM

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

Mr. C. 09-12-2008 10:57 AM

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.

ufmale 09-13-2008 12:21 AM

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 05:00 AM.