man*_*nes 0 variables bash x264
我使用 x264 脚本进行一些视频编码。大多数选项都遵循模式
\n\nx264 --option0 $value0 --option1 $value1 -o output.file input.file\nRun Code Online (Sandbox Code Playgroud)\n\n该脚本从文本文件中读取值。该文本文件包含键值,例如crf=18.3. 不幸的是,这不适用于 mb-tree,因为该选项没有 $value,它是默认设置的,可以通过以下命令关闭--no-mbtree。
如果mbtree=no-mbtree在文本文件中设置,则一切正常。但是,如果我选择在打开 mbtree 的情况下进行编码,则--$variable-for-mb-tree-or-no-mb-tree仍然存在,但未设置或为空,并且 x264 会引发错误。
我如何告诉 bash/ x264 忽略未设置或空变量?我想避免 if\xe2\x80\xa6then\xe2\x80\xa6else 而是内联执行。
\n您可以在参数扩展中使用替代值:
mycommand ${myvar:+ "--$myvar"}
Run Code Online (Sandbox Code Playgroud)
如果myvar=foo,这将运行mycommand --foo
如果myvar未设置或为空,它将mycommand在没有标志的情况下运行。