[ 已解決 ] 如何用 script 處理名字帶有空格的檔案

我打算用 script 去批量壓片,我現在用的是 script 如下

#!/bin/bash
for file in `ls`
do
ffmpeg -i $file -vcodec libx264 -a acc -strict -2 output/$file.mp4
done

(我知道那個 output directory 和 script 本身也是會被 script 處理啦,但這不是重點)
重點是… 很不巧,我的檔案都是 01 a.ts, 02 b.ts 之類,所以結果只會是

mv: cannot stat ‘01’: No such file or directory
mv: cannot stat ‘a.ts’: No such file or directory
mv: cannot stat ‘02’: No such file or directory
mv: cannot stat ‘b.ts’: No such file or directory

我想問一下要如何才能正確處理這些檔案呢?

for file in ls

上面插一句

rename ’ ’ ‘_’ *

感謝… 問題已解決