如何在shell脚本中运行此命令

时间:2011-01-21 13:31:01

标签: linux shell x264 mplayer

这是我的shell脚本,但它会出错:

#!/bin/sh

while getopts "i:o:" flag
do
   case $flag in
   i) file_input=$OPTARG
   ;;
   o) file_output=$OPTARG
   ;;
   esac
done

mplayer -nosound -benchmark -vo yuv4mpeg:file=>(x264 --demuxer y4m \
              --crf 20 --threads auto --output $file_output - ) $file_input

错误消息是:

  

无法获取内存或文件句柄来写“>(x264 --demuxer y4m --crf 20 --threads auto --output video.264 - )”!致命:无法初始化视频驱动程序。

当我在putty上运行这个cmd时:

mplayer -nosound -benchmark -vo yuv4mpeg:file=>(x264 --demuxer y4m \
              --crf 20 --threads auto --output video.264 - ) video.wmv

它完美无缺..

我做错了什么?

3 个答案:

答案 0 :(得分:4)

您正在使用的命令使用复杂的bash的pipe stream to subshell语法,即>()来实现您想要的效果。可能你的/bin/sh(你在shebang中作为这个脚本的shell调用)与你以交互方式使用的shell(即bash)不同?

答案 1 :(得分:1)

>(...)进程替换运算符是特定于Bash的。如果将Bash称为/bin/sh,它也不可用,因为在这种情况下,Bash将自己限制为更符合其功能的子集。

只需在脚本开头使用#!/bin/bash代替#!/bin/sh

答案 2 :(得分:0)

我建议您添加一些'以保护您的特殊字符:

mplayer -nosound -benchmark -vo 'yuv4mpeg:file=>(x264 --demuxer y4m --crf 20 --threads auto --output $file_output - )' $file_input