我需要检查哪个子模块“使用”了特定的原始网址我正在尝试做这样的事情:
check_url="some_url"
git submodule foreach --recursive 'if [$(git remote get-url origin)==$check_url];then echo "YES" else echo "NO" fi'
现在我收到错误消息
Syntax error: end of file unexpected (expecting "fi")
怎么了?
谢谢
您忘记了if
语句中的分号:
git submodule foreach --recursive 'if [$(git remote get-url origin)==$check_url];then echo "YES"; else echo "NO"; fi'
[if
语句中不仅需要分号,而且括号之间也需要空格。开头的括号[
实际上是test
命令的符号链接,因此,它需要与其他命令分开,结尾的括号(]
)也是如此。
此外,使用==
作为比较是一种轻信,并且不能移植到其他shell中,这意味着这在大多数Debian或Ubuntu系统上不起作用。最后,最佳做法是在测试参数周围加上双引号,这样,如果它们为空或包含多个单词,就不会出现解析错误。
因此它应该看起来像这样:
git submodule foreach --recursive 'if [ "$(git remote get-url origin)" = "$check_url" ]; then echo "YES"; else echo "NO"; fi'