Re: the old spaces in file names thingy in shell scripts

トップ ページ
添付ファイル:
Eメールのメッセージ
+ (text/plain)
このメッセージを削除
このメッセージに返信
著者: Bill Jonas
日付:  
To: plug-discuss
題目: Re: the old spaces in file names thingy in shell scripts
On Thu, Oct 11, 2007 at 09:23:16AM -0700, Craig White wrote:
> #!/bin/sh
> #
> BASE="/home/storage/users/craig/Desktop/dw"
> IN="in"
> OUT="out"
> for f in *.flv; do
> MP4=`basename "$f" .flv`.mp4
> ffmpeg -i "$f" "$MP4"
> mv "$f" "$BASE/$IN"
> mv "$MP4" "$BASE/$OUT"
> done


To use a bash-specific feature, you could rewrite it as follows:

#!/bin/bash
BASE="/home/storage/users/craig/Desktop/dw"
IN="in"
OUT="out"
for f in *.flv; do
ffmpeg -i "$f" "${f//flv/mp4}"
mv "$f" "$BASE/$IN"
mv "${f//flv/mp4}" "$BASE/$OUT"
done

It saves a process or two each time through the loop at the expense of
some portability. See the "Parameter Expansion" section in bash(1) for
more details.

-- 
Bill Jonas    *        *    http://www.billjonas.com/
"It's a dangerous business, Frodo, going out your front door.  You step
into the Road,  and if you don't keep your feet,  there  is  no knowing
where you might be swept off to."  --  Bilbo Baggins
---------------------------------------------------
PLUG-discuss mailing list - 
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss