下面的脚本..只是想练习一些bash的技能和做出快速util的我的中国MP4播放器=)Bash脚本:无法执行mencoder命令!
#!/bin/bash
#####################################
# RockChip 4gb Player mencoder preset
#####################################
TOOL='mencoder'
OUTS='./out/'
OPT1='-noodml'
OPT2="-of avi -ofps 22 -vf-add scale=320:-2,expand=320:240 -srate 44100 -ovc xvid -xvidencopts bitrate=400:max_bframes=0:quant_type=s16le -oac lavc -lavcopts acodec=mp2:abitrate=128"
bold=`tput bold`
normal=`tput sgr0`
# check does argument exists
if test -z "$1"; then
echo "There's no file given =)"
fi
# Check is it dir or file
if [ -d $1 ]; then
echo "Directory is given: $1"
# Test if output argument is given
if [ -z $2 ]; then
echo "No output argument given using default: ${bold}${red}$OUTS${normal}"
mkdir out
else
# test is given path a directory
if [ -d $2 ]; then
OUT="$2"
else
echo "Output argument is not a directory"
fi
fi
OLD_IFS=IFS; IFS=$'\n'
for file in `find . -name "*.*" -type f | sed 's!.*/!!'` ; do
file=`printf "%q" "$file"`
echo ${TOOL} ${OPT1} ${file} -o ${OUTS}${file} ${OPT2}
done
IFS=OLD_IFS
fi
问题是这一行:
echo ${TOOL} ${OPT1} ${file} -o ${OUTS}${file} ${OPT2}
当您删除回音,以执行命令,命令失败,但如果您将复制此回显脚本,并手动执行它,一切正常。
当从shell脚本输出执行命令:
MEncoder 1.0rc4-4.2.1 (C) 2000-2010 MPlayer Team
158 audio & 340 video codecs
-of avi -ofps 22 -vf-add scale=320:-2,expand=320:240 -srate 44100 -ovc xvid -xvidencopts bitrate=400:max_bframes=0:quant_type=s16le -oac lavc -lavcopts acodec=mp2:abitrate=128 is not an MEncoder option
Exiting... (error parsing command line)
我执行命令manualy一切正常,比如前面提到的:
mencoder -noodml 12\ I\ Love\ You\ 1\ \ I\ Love\ You\ 2\ \ I\ Love\ You\ 3.avi -o ./out/12\ I\ Love\ You\ 1\ \ I\ Love\ You\ 2\ \ I\ Love\ You\ 3.avi -of avi -ofps 22 -vf-add scale=320:-2,expand=320:240 -srate 44100 -ovc xvid -xvidencopts bitrate=400:max_bframes=0:quant_type=s16le -oac lavc -lavcopts acodec=mp2:abitrate=128
现在我能做的就是复制粘贴生成的命令问题在哪里?我试图谷歌真的很难..没有结果......(我知道mencoder的个人资料的..这不是我想要他们的情况下)(37行,我相信)
的分配来OLD_IFS和IFS缺少在RHS一个美元符号,和RHS也应包含在双引号:'OLD_IFS =“$ IFS”; IFS = “$ OLD_IFS”'。但是,由于脚本即将退出,因此重置值无关紧要(因此无论如何也无关紧要)。 – 2011-04-21 04:47:14