之间有什么区别.和./在bash中? [英] What is the difference between . and ./ in bash?

查看:107
本文介绍了之间有什么区别.和./在bash中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行此命令(其中a.out是有效的C可执行文件):

Running this command (where a.out is a valid C executable):

. a.out

...导致此错误:

bash:.:a.out:无法执行二进制文件

bash: .: a.out: cannot execute binary file

但是,运行以下命令:

./a.out

...成功执行了C二进制可执行文件.

...successfully executes the C binary executable.

很明显,这里有两种执行方式,有什么不同?

Clearly, there are 2 types of executions happening here, what's different?

推荐答案

shell使用空格分隔要运行的命令及其参数.

The shell uses spaces to separate the command to run and its parameters.

在第一个示例中,要运行的命令是.,其参数为a.out. .命令是source的shell快捷方式,该快捷方式将包含shell命令的文件名作为第一个参数,并在当前shell中运行这些命令.该命令失败,因为a.out是二进制文件,而不是Shell脚本.

In the first example, the command to run is . with a parameter of a.out. The . command is a shell shortcut for source, which takes the name of a file containing shell commands as its first parameter and runs those commands in the current shell. This command fails because a.out is a binary file, not a shell script.

在第二个示例中,要运行的命令是./a.out,这意味着运行当前目录中的文件a.out.

In the second example, the command to run is ./a.out, which means run the file a.out residing in the current directory.

这篇关于之间有什么区别.和./在bash中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆