1
A
回答
2
假设这是一个POSIX壳(如bash)的,你可以写这样的事:
cc "$2"
if [ $? = 0 ] ; then
# . . . commands to run if it compiled O.K. . . .
else
# . . . commands to run if it failed to compile . . .
fi
或略偏简洁:
if cc "$2" ; then
# . . . commands to run if it compiled O.K. . . .
else
# . . . commands to run if it failed to compile . . .
fi
在特殊情况下,你根本如果编译失败,想运行某个命令,例如exit 1
,你可以写这样的:
cc "$2" || exit 1
0
在Bash - shell
您可以直接使用下面的,没必要的if
cc $2
[ $? -ne 0 ] && exit 1
# rest of code
,或者您可以使用,
cc $2
if [ $? -eq 0 ]; then
# code for true
else
# code for false
fi
相关问题
- 1. shell脚本的编译器
- 2. 从shell脚本编译库
- 3. 编写shell脚本的shell脚本
- 4. 编译C#脚本很慢
- 5. 脚本编译C代码
- 6. 如何使用Shell脚本为c编译器创建别名?
- 7. Bash shell脚本,用于编译C++和操纵输出
- 8. 编写shell脚本
- 9. 使用c编程运行shell脚本
- 10. 编译脚本
- 11. GUI shell脚本编辑器
- 12. 如何编写shell脚本?
- 13. Shell脚本不编码ASCII
- 14. 如何编写shell脚本
- 15. “编译” Python脚本
- 16. 如何编译游戏的C#脚本
- 17. nant脚本c#编译错误
- 18. 用于编译C++的脚本
- 19. bash脚本来编译和运行C++
- 20. c shell脚本解释
- 21. 运行shell脚本由C
- 22. Unity c#运行shell脚本
- 23. 从C调用shell脚本
- 24. 如何搜索.c文件的子目录并编译它们(shell脚本)
- 25. 用于编译和生成C文件输出的Shell脚本文件
- 26. 编译shell脚本,使它完全不可读
- 27. 有没有办法使用“SHC”在OSX上编译shell脚本?
- 28. 如何在编译时将shell脚本输出到Makefile.am中?
- 29. 如何使用Shell脚本编写shell脚本来查找shell类型
- 30. shell的shell脚本
检查'$ ?'等于0? – chrisaycock
谢谢。我会试试看。 – J0natthaaann
看看返回代码,并做你需要做的。看看一个shell教程。 –