[Bash Scripting] About redirecting an output
Joel Bryan Juliano
joelbryan.juliano at gmail.com
Sun Feb 25 01:27:25 UTC 2007
On 2/25/07, Ouattara Oumar Aziz <wattazoum at gmail.com> wrote:
> hi,
>
> I have written a nautilus script that I use on my computer to convert
> some videos to avi. The script runs well for me but I would like to
> share it and I want to get rid of some little problems :
>
> 1. How do I get "mencoder" percentage to pipe it to zenity ? I have
> tried a lot but I can't.
>
> 2. How do I bind zenity --progress cancel button to the task so that
> when I press cancel it cancels or kill the task ?
>
> Thanks
>
>
>
>
>
> #!/bin/sh
> # Author :Ouattara Aziz
> # Date : 31/12/2006
> #depends: mplayer, zenity,tree
> #version 0.1
>
> #test si un fichier a Ã(c)tÃ(c) choisi
> if [ $# -eq 0 ]; then
> zenity --error --title="error" --text="SÃ(c)lectionnez au moins un fichier"
> exit 1
> fi
>
> #montre la fenètre de sÃ(c)lection de dossier de destination
> title="Choisissez votre dossier de destination"
> destdir=`zenity --title "$title" --file-selection --directory | sed 's/ max//g' `
>
> #if $? != 0, user click on cancel button, so exit
> if [ "$?" != 0 ] ; then
> exit
> fi
>
> #Selectionnez le dossier de destination
> if [ ! "$destdir" ]; then
> zenity --error --title="error" --text="SÃ(c)lectionnez un dossier de destination"
> exit
> fi
>
> # si on a juste un fichier sÃ(c)lectionnÃ(c) (donc pas un rÃ(c)pertoire) .
> if [ ! -d "$1" ]
> then
> echo "# traitement video $1 ..."
> mencoder -idx "$1" -ovc x264 -oac mp3lame -o "$destdir/$1.avi" | while read LINE ;
> do
> echo "# $LINE"
> done | zenity --progress --auto-close --pulsate
> else
> ORIGDIR=`echo "$1" | sed 's/ /\\ /g'`
>
> tree -if "$ORIGDIR" | head -n -2 | while read FILE;
> do
> # VÃ(c)rification du type de fichier
> if [ -d "$FILE" ]
> then
> mkdir "$destdir/$FILE";
> else
> echo "# traitement video $FILE ..."
> mencoder -idx "$FILE" -ovc x264 -oac mp3lame -o "$destdir/$FILE.avi"
> fi
> done | zenity --progress --auto-close --pulsate --title="conversion" --text="Conversion des vidÃ(c)os" --percentage=0
> fi
>
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
>
if your going to use #!/bin/sh, you need to explicitly define your syntax.
for example in bash this is fine.
if [ -z $MY_CONDITION ]; then
foo
fi
but in dash, it's not.
you'll have to put the semicolon delimiter on every command.
also, for functions this is fine with bash
function name {
...
}
but dash syntax should be
name () {
...
};
for redirecting in dash with zenity, I think this is fine.
{ command1; command2; command3; } > $ZENITY
or
( command1; command2; command3; ) | $ZENITY;
Hope this helps!
Joel
--
"I use to fuel my car with water, now I switched back to gasoline
because my cigarette lighter doesn't work" - People who use Linux but
switched back to Windows.
More information about the ubuntu-users
mailing list