如何查明cshell中是否存在shell命令
我正在寻找一个函数,如果 shell 命令存在,则返回 1,否则返回 0 我知道有 which
命令可以返回命令的路径(如果存在)。手册中还说该命令应该有返回值,但尝试 set a = `which some_command.bin`
不会将任何值放入 a
中。 我知道我总是可以使用 which
然后解析结果,我只是在寻找更干净的解决方案
I'm looking for a function that would return 1 if a shell command exists, and 0 otherwise
I know there is the which
command that returns the path of a command if it exists. It also says in the manual that this command is supposed to have a return value, but trying
set a = `which some_command.bin`
doesn't put any value into a
.
I know that I can always use which
then parse the results, I'm just looking for a cleaner solution
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
shell 命令的返回值通常不是这样检索的。您通常需要运行该命令,然后特殊的环境变量
$?
将为您提供返回值。请参阅以下
tcsh
的文字记录:只需将您想要检查的任何命令放入上面的
ls
位置即可。The return value for a shell command is not usually retrieved like that. You generally need to run the command, then the special environment variable
$?
will give you the return value.See the following transcript for
tcsh
:Just put whatever command you want to check for where I have
ls
above.