complex command substitution


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting complex command substitution
# 1  
Old 05-21-2006
complex command substitution

hi,
I have to execute this line below from within a shell script; simply backquoting it is not doing the trick; it is mangling up all the options; but when i type it out on a command line, it executes cleanly. Please help me in getting this right;

$ vlc -I dummy --sout='#transcode{vcodec=mp4v, acodec=mp4a}:std{access=file, mux=mp4, url=temp.mp4} file.avi

As you can see, the syntax of the option specification for VLC includes many complex tokens; Can you guide me to get it working from within backquotes?

Thanks!
# 2  
Old 05-21-2006
Incredible that it works at all. What shell are you using? Most shells will choke on an unmatched single quote.
# 3  
Old 05-21-2006
oops!

ok, there is no unmatched single quote; thanks a lot for pointing out; this is the corrected command line:

$ vlc -I dummy --sout='#transcode{vcodec=mp4v,acodec=mp4a}:std{access=file,mux=mp4,url=temp.mp4} ' file.avi

I got this partially working by simply writing the line in the shell script (without an backquotes). The problem is my temp.mp4 and file.avi are actually inside variables $T and $F; something like this works:

#!/bin/sh

#do some string manipulation to determine values of $T and $F

vlc -I dummy --sout='#transcode{vcodec=mp4v,acodec=mp4a}:std{access=file,mux=mp4,url=temp.mp4} ' "$F"

but if I replace $T for temp.mp4, it wont work anymore; I dont care about the return value of this command, so I dont need backquotes;

So, the problem has boiled down to - how do I make the shell interpret the $ variable inside those single quotes?

Thanks!
# 4  
Old 05-24-2006
What you need to do is pre-process the command line within the single quotes, performing variable substution. I don't know about your application, so here is a trivial example which should make it clear.

There is a one line script called z containing the line "print $1"
There is a variable within the current shell with the value "z" (a=z)
First run z with $a as a parameter and it prints "z" (value substituted)
Code:
$ ./z $a
$ z

Next run z with '$a' as a parameter and it prints "$a" (value not substituted because it's in single quotes)
Code:
$ ./z '$a'
$ z

Finally, run with eval and value is substuted even though in quotes (substitution is actually done as a separate step before command is executed)
Code:
$ eval ./z '$a'
$ z

hope this helps
# 5  
Old 05-24-2006
Could you not just unquote at the point you need the variable interpolation:

vlc -I dummy --sout='#transcode{vcodec=mp4v,acodec=mp4a}:std{access=file,mux=mp4,url='$T'} ' "$F"

Does that work?
# 6  
Old 05-24-2006
hi all, thanks a lot, I solved the problem with some generous usage of quotes..
vlc -I dummy --sout=""#transcode{vcodec=mp4v,acodec=mp4a}:std{access=file,mux=mp4,url=$T} "" $F

did the trick; the problem was that I needed some kind of quotes after --sout= as part of the commad line syntax;
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Complex grep command

Hallo Team, I need your help and its rather urgent. I have a file with thousands of lines. Here is a sample below: Sample1.txt BW235045560121114833444044@196.35.130.5 BW235106757121114-574455394@196.35.130.5 BW2349514941211141077771352@196.35.130.5... (5 Replies)
Discussion started by: kekanap
5 Replies

2. UNIX for Dummies Questions & Answers

read command - using output from command substitution

Hey, guys! Trying to research this is such a pain since the read command itself is a common word. Try searching "unix OR linux read command examples" or using the command substitution keyword. :eek: So, I wanted to use a command statement similar to the following. This is kinda taken... (2 Replies)
Discussion started by: ProGrammar
2 Replies

3. UNIX for Dummies Questions & Answers

sed insert command and variable expansion/command substitution

I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename? #!/bin/bash filename=`echo $0` /usr/bin/sed '/#include/ { i\ the filename is `$filename` }' $1 exit 0 (8 Replies)
Discussion started by: glev2005
8 Replies

4. Shell Programming and Scripting

find command with complex logic

I'm looking to write a script that will do a find of directories and delete them if they are older than x days but keep the last x # of folders even if they are older than x days. The usage is for a deployment location, so we want to keep the location clean but retain maybe the last 2 builds that... (5 Replies)
Discussion started by: MaureenT
5 Replies

5. UNIX for Advanced & Expert Users

complex find command

Hi all, I am trying to execute the following command: find 'path' -ls -exec cksum {} \; As you can see this simply finds files from a given path and runs cksum on them. My problem is this, if i have a FIFO in a directory the find tries to execute cksum on it and gets stuck. From the man page i... (9 Replies)
Discussion started by: noam128
9 Replies

6. Shell Programming and Scripting

Complex Email command in unix

Folks, I have two files, i.e. one.txt and two.dat on unix file system. I need to include the contents of one.txt in the body of the email to the sender and attach two.dat in the same email as an attachment using ksh commands, mailx or uuencode etc... I know how to send them seperately but I... (2 Replies)
Discussion started by: calredd
2 Replies

7. Shell Programming and Scripting

Complex find grep or sed command

Haven't worked in bash for ages. did a good bit of shell scripting in regular sh, but have forgotten most of it. I have several thousand php files that now include the following line at the end of the file. There is no LF or CR/LF before it begins, it is just concatenated to the final line of... (3 Replies)
Discussion started by: sjburden
3 Replies

8. Shell Programming and Scripting

complex grep command

hi all i have file call "list.log" which contains like this 00300 000024501043846 0 00300 000034531322871 0 00600 000000489100734 0 and so on .. the file goes like this:(example first row) from position 1-5 the lider number(300),position 7-21 id... (0 Replies)
Discussion started by: naamas03
0 Replies

9. UNIX for Dummies Questions & Answers

vi/vim : complex pattern substitution

I use vim. I have a lot of SQL queries to write, and am hoping there is some wild command I can use in vim to make this simpler. From a file that is a list of fields, like the excerpt, for example: orderdetail.ccntyfips orderdetail.citemord orderdetail.coffdetid I want to go to this: ... (2 Replies)
Discussion started by: c444l
2 Replies

10. Answers to Frequently Asked Questions

advanced/complex uses of the find command

Perhaps the number one advanced find question is: How to stop find from descending into subdirectories? find command Performing a non-recursive find in Unix Use -prune with find command on AIX Searching for files over 30 days old in current directory disk space used for files with in a... (0 Replies)
Discussion started by: Perderabo
0 Replies
Login or Register to Ask a Question