这段shell是什么意思,到处没查到资料

太上绝情 2017-06-23 07:52:31
这个是ffmpeg的configure脚本的开头几行,无法理解是什么意思,尤其是那个小括号是什么语法

unset foo
(: ${foo%%bar}) 2> /dev/null
E1="$?"

(: ${foo?}) 2> /dev/null
E2="$?"

用sh -x执行也没看出什么有用的信息。



if test "$E1" != 0 || test "$E2" = 0; then
echo "Broken shell detected. Trying alternatives."
export FF_CONF_EXEC
if test "0$FF_CONF_EXEC" -lt 1; then
FF_CONF_EXEC=1
try_exec bash "$0" "$@"
fi
if test "0$FF_CONF_EXEC" -lt 2; then
FF_CONF_EXEC=2
try_exec ksh "$0" "$@"
fi
if test "0$FF_CONF_EXEC" -lt 3; then
FF_CONF_EXEC=3
try_exec /usr/xpg4/bin/sh "$0" "$@"
fi
echo "No compatible shell script interpreter found."
echo "This configure script requires a POSIX-compatible shell"
echo "such as bash or ksh."
echo "THIS IS NOT A BUG IN FFMPEG, DO NOT REPORT IT AS SUCH."
echo "Instead, install a working POSIX-compatible shell."
echo "Disabling this configure test will create a broken FFmpeg."
if test "$BASH_VERSION" = '2.04.0(1)-release'; then
echo "This bash version ($BASH_VERSION) is broken on your platform."
echo "Upgrade to a later version if available."
fi
exit 1
fi

接下来对于E1和E2的判断处理也没看懂是要干什么
...全文
1146 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ForestDB 2017-08-16
  • 打赏
  • 举报
回复
unset foo (: ${foo%%bar}) 2> /dev/null E1="$?" (: ${foo?}) 2> /dev/null E2="$?" 这些东西都能在man bash中找到。 unset就是取消变量,比如 $ foo=1 $ echo $foo 1 $ unset foo $ echo $foo # 由于foo被unset了,所以这里回显为空 $ 2>/dev/null 将标准错误重定向至空,即丢弃标准错误输出 ${foo%%bar} 这是Parameter Expansion, ${parameter%word} ${parameter%%word} Remove matching suffix pattern.移除匹配的后缀模式,比如 $ foo=readme.txt $ echo ${foo%.txt} readme $ echo ${foo%%.txt} readme %和%%的区别在于%%删除尽可能长的匹配(贪婪模式) : 这是SHELL BUILTIN COMMANDS,即shell的内置命令 : [arguments] No effect; the command does nothing beyond expanding arguments and performing any specified redirections. A zero exit code is returned. :相当于其他语言中的空语句,比如C中的;; : ${foo%%bar} 什么也不做,只是做上面的参数扩展,且语句总返回0 ()是shell中的Compound Commands,复合命令 (list) list is executed in a subshell environment,即在子shell中执行命令 The return status is the exit status of list.即()的返回值是其中执行命令的返回值, 由上,: ${foo%%bar} 的返回值是0 $?是Special Parameters ? Expands to the exit status of the most recently executed fore‐ ground pipeline. 即上个命令的返回状态 由此,E1应该总为0 ${foo?}是另一种Parameter Expansion ${parameter:?word} Display Error if Null or Unset. If parameter is null or unset, the expansion of word (or a message to that effect if word is not present) is written to the standard error and the shell, if it is not interactive, exits. Otherwise, the value of parameter is substituted. Omitting the colon results in a test only for a parameter that is unset. 所以这里是检测foo是否为unset,如果是,则在标准错误上打出一条消息(因为这里?后面没有提供word) 注意这里的:是会返回1的,和文档中记载的不一致,有点奇怪 null和unset的区别 unset foo 这时foo是unset的 foo= 这时foo是null的
ipqtjmqj 2017-06-23
  • 打赏
  • 举报
回复
ipqtjmqj 2017-06-23
  • 打赏
  • 举报
回复
你把小括号去掉看看会报什么错

3,286

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 实用资料发布区
社区管理员
  • 实用资料发布区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧