Bash trick of the day
John Abreau
abreauj at gmail.com
Mon Apr 2 11:55:55 EDT 2007
On 4/2/07, Eric C <eric at newmag.org> wrote:
> "No. Why would you expect it to exit in 120 seconds?
> -dsr-"
>
> Because
> WAIT_SECONDS=$(($WAIT_MINUTES * 60))
>
> "Can you show me the exact line you typed in?"
> - David
>
> I just saved your script as davidKramer.sh and changed
> to variables in the top.
>
> cat /dev/video0 > /tmp/test_capture.mpg=$1
> 2=$2
>
> In terminal I merely typed the path to davidKramer.sh
> and it starts recording but no other messages.
If that's literally what you changed in the script, then of course it
doesn't work.
COMMAND=$1
sets the variable COMMAND to the first parameter, and this variable is
then used to launch the desired command and later to kill it. If you
literally changed this to
cat /dev/video0 > /tmp/test_capture.mpg=$1
then the script starts by running the command
cat /dev/video0
and writes tis stdout to "/tmp/test_capture.mpg=" plus the first parameter
to the script. For instance, if you ran the script as
./davidKramer.sh foo bar
then the video stream would be written to the file
"/tmp/test_capture.mpg=foo"
The rest of the script won't even run until the "cat" command finishes
running. If you had used a command that exited normally, and run
the script as
./davidKramer.sh foo bar
then the next command in the script,
2=$2
would give an error
2=bar: command not found
After that the script would find that the variables COMMAND and
WAIT_MINUTES are undefined, and it would terminate with the
error message
No command specified
Usage: ./davidKramer.sh <command to run> <minutes to run for>
--
John Abreau / Executive Director, Boston Linux & Unix
GnuPG KeyID: 0xD5C7B5D9 / Email: abreauj at gmail.com
GnuPG FP: 72 FB 39 4F 3C 3B D6 5B E0 C8 5A 6E F1 2C BE 99
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
More information about the Discuss
mailing list