[ale] [Slightly OT] Help with a quick shell script?

Charles Shapiro hooterpincher at gmail.com
Wed Aug 16 10:20:15 EDT 2006


Uh, have you experimented with the bash "IFS" variable?  ${IFS} is what the
for loop uses to separate its words. By default it is space, tab, or
newline. But changing the line "IFS="\n" will make it newline only.  My
advice is to set it back immediately after you're done or much wacky fun may
ensue.

-- CHS


On 8/16/06, fd0man??The Magical Floppy Man <fd0man at gmail.com> wrote:
>
>  I cannot seem to figure this out.  I am attempting to write a small shell
> script that I can use from within Nautilus to convert MP3 files to Ogg
> Vorbis, with just a right-click.  However, I cannot get the thing to work
> for paths/file names with spaces in them.  Since most people I know name
> their files with spaces, it is a case that I would like to handle.  Here is
> the script as I currently have it:
>
> files=$(echo -e "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | awk 'BEGIN { FS = "\n" } { printf "\"%s\" ", $1 } ' | sed -e s#\"\"##)
>
> for mp3file in $files
>  do
>   echo "Processing file ${mp3file}?"
>   file "$mp3file" | grep '(MP3)|(MPEG)' > /dev/null
>   if [ $? -eq 0 ];
>    then
>     echo "Debug:  File is an MP3 file.  Going ahead with the conversion?";
>     NewMusicFileName=`echo $mp3file | sed 's/\.mp3/\.ogg/g;'`
>     TmpMusicFileName=`echo $mp3file | sed 's/\.mp3/\.ogg/g;'`
>     mpg123 -w - "$mp3file" | oggenc - -o $NewMusicFileName
>   fi
>  done
>
>
> GNOME (specifically, Nautilus) states that
> NAUTILUS_SCRIPT_SELECTED_FILE_PATHS is a newline-delimited list of paths for
> the selected files int he window.  However, it seems that bash, when using a
> for loop on the environment variable, do not break it apart by lines, but
> instead by word.  Is there a way that anyone knows to take the environment
> variable, and use each whole line of it within a for-style loop like this?
>
> The output that I am getting from this script at this time is:
>
> fd0man at pepper:~/Downloads$ NAUTILUS_SCRIPT_SELECTED_FILE_PATHS='/home/fd0man/Downloads/51 - Shakira - Hips dont lie ft Wyclef Jean.mp3' ogg_convert_test
> Processing file "/home/fd0man/Downloads/51?
> Processing file -?
>
>
> Where it hangs on the second line until I press C-c or C-d.  If I press
> C-d, it proceeds to go through the rest of the parts of the file name.
> *shrugs*  It would be nice if there were a for variant that worked on lines
> instead of words, but if there is, the man page isn't telling me about it?
>
>     ? Mike
>
> --
>   The fd0man??The Magical Floppy Man! (fd0man at gmail.com) *"One world, one
> web, one program"  ?Microsoft promotional ad *
> *"**Ein** Volk, **ein** Reich, **ein** Fuehrer"  ?Adolf Hitler *
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...




More information about the Ale mailing list