LoginSignup
5
6

More than 5 years have passed since last update.

シェルスクリプトでスペースや改行が入っているファイル処理するときには、IFSを設定する。

Posted at

IFSを設定する

mp4tomp3.sh
#!/bin/bash

IFS=$'\n'

files=$(find . -type f -name "*.mp4")

for file in $files
do
    file_without_extension=${file%.*}

    echo "change from "${file}" to "${file_without_extension}.mp3
    ffmpeg -i $file -acodec libmp3lame -ab 64k -ac 1 ${file_without_extension}.mp3
done

明示的にIFSを設定することで for ループでスペースなどを含んだファイルを処理するときにファイル名が分割されることがない。

参考

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6