Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
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.
Distribution: Ubuntu Intrepid and Meerkat, formerly used Debian 3.1 (Sarge) with Gnome Desktop
Posts: 353
Rep:
Help with Bash scripts
Hello all,
I have written a bash script which counts the number of lines in a given text file, and then chooses a random number and then reads the line number from the file basis that random number. The script looks like this:
Lets say the content of each line in myfile was a bunch of parameters or options for Xine. And lets say that I want my script to launch Xine using the contents of the line that was read by sed. How would I finally use xine in my script?
I tried adding as the last line in my script :
Code:
xine ${LINE}
But xine is not accepting the parameters.
HOWEVER, If I echo first:
Code:
echo xine ${LINE}
then I can copy and paste the line that was echoed into the terminal window and Xine executes properly using the correct switches.
I really hope someone can help.
Last edited by greengrocer; 06-04-2009 at 07:46 AM.
I also know that when I run my BASH script, $LINE actually does look like: --enqueue -S session=0,mrl=/home/user/kelly.mpg#volume:100
but for some reason, if I try to use:
xine ${LINE}
The contents of $LINE are not treated as one bunch of parameters. I have a funny feeling that xine is trying to treat $LINE as just an MRL, which $LINE is more than just an MRL.
I have also tried (with $LINE = /home/user/kelly.mpg#volume:100 (hence, just the valid url with a volume setting on the end which is allowed when using the enqueue option)
xine --enqueue -S session=0,mrl=${LINE}
Last edited by greengrocer; 06-04-2009 at 07:44 AM.
Works. I'm not a bash-scripter so what do the curlies do?
I've discovered that:
Code:
xine "$LINE"#volume:10
will work, so long as the line from the file looked like this:
/home/user/kelly.mpg
which is kind of nearly what I want, only that:
the line from the file MUST have a volume specifier at the end, so the line from the file has to look like this:
/home/user/kelly.mpg#volume:10
So my next question would be, if I use sed to get read the line and print the line to $LINE. How could I strip the #volume:10 from it and make $VOL = #Volume:10 ?
Gosh I hope this has made sense to someone, coz its difficult to describe.
If that doesn't work, try adding a set -x between the echo and xine statement, that should show you what bash does and how xine is executed.
Well, that throws some light onto whats going wrong (I could see that #volume:10 was being treated as part of the MRL and also adding a ' to where ever there was a space in a file name). Soooo, basically if I use:
xine "$LINE" seems to work with everything including file names that have spaces, so long as I dont have the #volume:10 on the end of the line.
However, I need the volume argument on the end of the line, and I need to pass that as an arg to xine (some files are louder than others you see). So if I can just know how to separate the two pieces of information into two separate variables, I think it might do the trick.
So close to what I need, I can smell it.
Last edited by greengrocer; 06-04-2009 at 08:31 AM.
The # in the options line could be (is??) seen by bash as special when using ${LINE} (man bash for the details). That is why $LINE works (more or less) and ${LINE} does not.
Distribution: Ubuntu Intrepid and Meerkat, formerly used Debian 3.1 (Sarge) with Gnome Desktop
Posts: 353
Original Poster
Rep:
Quote:
Originally Posted by druuna
Hi,
The # in the options line could be (is??) seen by bash as special when using ${LINE} (man bash for the details). That is why $LINE works (more or less) and ${LINE} does not.
Maybe my eval option helps......
Yeah cool, I also think that if I read a line from a file that looks like this:
/home/user/kelly.mpg#volume:100
and if I can use sed to put the above line into a variable called $TEMP
and then somehow split $TEMP into two pieces, so that:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.