#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Posts
    3
    Rep Power
    0

    Shell script not setting variables


    I'm /bin/sh as the shell for this script. I'm attempting to create a script that will automate the ripping of DVDs into a format to be named later. So far, I'm able to take the output of Mplayer/mencoder and create a file called "crop.txt".

    when I run the script, though, crop.txt is created, but the variables I want to set don't get set...

    what am I doing wrong? I'm sure it's something very minor...

    -------------------------------------------------------------------------------------------------------------
    #!/bin/sh

    mplayer -v -ss 00:15:00 -frames 20 -vf cropdetect dvd://1 > crop.txt

    CROP='tail -n 11 crop.txt | grep CROP | cut -d= -f2 | cut -c 1-11'
    -------------------------------------------------------------------------------------------------------------

    now, I've run these commands independently, and the output from

    "tail -n 11 crop.txt | grep CROP | cut -d= -f2 | cut -c 1-11"

    is "720:480:0:0". I want this set as $CROP, so that later in the script, I can call that variable.

    Any assistance is greatly appreciated...

    Please keep the scope to only /bin/sh. I have no interest in using csh, bash, or anything like that... /bin/sh is ubiquitous to all UNIX systems.

    Bryan
    Last edited by brakeb; March 8th, 2009 at 12:29 AM. Reason: added notification
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2008
    Posts
    96
    Rep Power
    141
    If you are going to run commands and assign the output to a variable you need to make sure you use the right quotes. ( i.e. the ones on the tilde[~] key ) I can't remember what they're actually called.. but here's your example with the correct quotes.

    CROP=`tail -n 11 crop.txt | grep CROP | cut -d= -f2 | cut -c 1-11`

    also, you can always run your script in debug mode to watch these things.

    sh -x ./script.sh

    or change the shebang to

    #!/bin/sh -x

IMN logo majestic logo threadwatch logo seochat tools logo