git - c shell脚本检查Git在系统中是否可用

标签 git shell scripting csh

我目前正在创建一个脚本,对我们的软件框架的文件进行一些操作。现在我们已经转移到 Git,这个脚本需要设置一些功能(即:忽略某些文件的本地更改)。

所以我想用这个 C shell 脚本来检查系统中是否安装了 Git,然后再执行某些 Git 操作,以便向后兼容其他未安装 Git 的系统。

我正在考虑使用 whichwhereis 但我似乎无法将其与 C shell if() 语句集成。

最佳答案

如果您确实需要csh,这有效:

if ( -x `which git` ) then
    ... what to do if it can be run ...
else
    ... what to do if it cannot
endif

-x 测试检查给定路径是否可执行,反引号运行 which 来查找路径(或打印 git: command not find,该文件不可执行)。

Carpetsmoker noted in comments ,如果您正在使用 tcsh(或者有一个实际上只是 tcsh 的 csh,例如现代 Mac 和 FreeBSD 上的情况),您可以使用:

if ( -X git ) then ...

不过,拥有一个理智的 shell 会更好。

关于git - c shell脚本检查Git在系统中是否可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32453289/

相关文章:

shell - "grep"从一行的最后 24 个字符中的前 12 个字符

linux - 尾部 : cannot open ‘+2’ for reading: No such file or directory

c++ - (C/C++ 的 latex 数学解析

variables - 期望具有可变主机名的脚本

Git checkout 因分离的工作树而失败

git - 如何在 merge 之前从第三方 fork 编辑 PR(而不是相信他们的代码)?

shell - 在oozie中计划/运行mahout命令

Python3 传递 Ruby 中等效的命令

git - 如何忽略已 checkin 的本地目录之一的更改?

git - 致命的 : Not a git repository (or any of the parent directories): . git