LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 09-12-2008, 12:44 AM   #1
ufmale
Member
 
Registered: Feb 2007
Posts: 385

Rep: Reputation: 30
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?
 
Old 09-12-2008, 01:04 AM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
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.
 
Old 09-12-2008, 01:12 AM   #3
Vit77
Member
 
Registered: Jun 2008
Location: Toronto, Canada
Distribution: Mandriva, RHEL, Mageia, SuSE
Posts: 130

Rep: Reputation: 17
You could deivide your line into two:

Code:
vol=`sox infile -n stat -v 2>&1`
cm=`sox infile outfile vol $vol`
 
Old 09-12-2008, 01:20 AM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
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.
 
Old 09-12-2008, 02:30 AM   #5
Vit77
Member
 
Registered: Jun 2008
Location: Toronto, Canada
Distribution: Mandriva, RHEL, Mageia, SuSE
Posts: 130

Rep: Reputation: 17
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 >.
 
Old 09-12-2008, 10:57 AM   #6
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
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.
 
Old 09-13-2008, 12:21 AM   #7
ufmale
Member
 
Registered: Feb 2007
Posts: 385

Original Poster
Rep: Reputation: 30
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`
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot execute script file from shell shahrahulb Linux - General 4 03-04-2008 07:02 AM
auto execute shell script ykirankumar Linux - Software 3 09-22-2004 07:23 AM
shell script won't execute brandnewbie Linux - Newbie 7 08-10-2004 01:30 PM
how to execute shell script with c code? khucinx Programming 3 05-04-2004 02:54 PM
shell script how to execute x2000koh Programming 6 07-29-2003 04:20 PM


All times are GMT -5. The time now is 12:00 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration