加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – Bash 19个字符没有任何理由消失

发布时间:2020-12-13 23:52:33 所属栏目:Linux 来源:网络整理
导读:我试图制作一个批处理脚本来压缩我的音频文件,我面临一个非常奇怪的问题. 这是我的代码: #!/bin/bashqscale=$1input=$2output=$3inputSize=$((${#input}+1))find "$input" -type f -name "*.flac" -print0 | while read -d $'' ado path=${a:inputSize} e
我试图制作一个批处理脚本来压缩我的音频文件,我面临一个非常奇怪的问题.

这是我的代码:

#!/bin/bash

qscale=$1
input=$2
output=$3
inputSize=$((${#input}+1))

find "$input" -type f -name "*.flac" -print0 | while read -d $'' a
do
    path=${a:inputSize}
    echo "Working on $path"
#    ffmpeg -i "$a" -qscale:a $qscale "$output/${path[@]/%flac/mp3}" &>/dev/null
done

这是一个结果示例:

Working on 09 - Groove #2 (instrumental studio outtake).flac
Working on 07 - Blues for Allah Sand Castles and Glass Camels Unusual Occurrences in the Desert.flac
Working on 12 - Proto 18 Proper (instrumental studio outtake).flac
Working on 04 - The Music Never Stopped.flac
Working on 13 - Hollywood Cantana (studio outtake).flac
...

如果我取消注释ffmpeg行,这是同一文件夹的结果:

Working on 09 - Groove #2 (instrumental studio outtake).flac
Working on h Sand Castles and Glass Camels Unusual Occurrences in the Desert.flac
Working on 12 - Proto 18 Proper (instrumental studio outtake).flac
Working on r Stopped.flac
Working on 13 - Hollywood Cantana (studio outtake).flac
...

两个文件中的一个文件错过了第19个第一个字符!而且我不知道为什么.

解决方法

取消注释ffmpeg行并在其上运行 shellcheck报告:

Line 12:
    ffmpeg -i "$a" -qscale:a $qscale "$output/${path[@]/%flac/mp3}" &>/dev/null
    ^-- SC2095: Add < /dev/null to prevent ffmpeg from swallowing stdin.

再试一次

ffmpeg -i "$a" -qscale:a $qscale "$output/${path[@]/%flac/mp3}" &>/dev/null < /dev/null

ffmpeg,以及ssh和mplayer,因读取循环时窃取stdin而臭名昭着.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读