运行没有点斜线的脚本(Ubuntu vs Mac) [英] Running scripts without dot slash (Ubuntu vs Mac)

查看:17
本文介绍了运行没有点斜线的脚本(Ubuntu vs Mac)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 ubuntu 中可以使用以下命令执行脚本:

In ubuntu scripts can be executed with following commands:

$ chmod +x manage.py
$ manage.py

但是在 mac 中你需要使用 ./ 来实际运行脚本,如下:

However in mac you need to use ./ in order to actually run the script, as follow:

$ chmod +x manage.py
$ ./manage.py

我想知道 ./ 到底是什么(尤其是两个系统默认都使用 bash)以及是否有办法直接在 mac 中运行脚本?

I would like to know what is exactly ./ (especially that both system use bash by default) and if there is a way to run scripts directly in mac?

推荐答案

这是因为您(非常明智地)在您的 PATH 环境变量中没有 . .如果你这样做了,它就会成为人们让你执行他们自己的代码而不是真正的代码的攻击媒介.

It's because you (very sensibly) don't have . in your PATH environment variable. If you do, it becomes an attack vector for people to get you to execute their own code instead of real stuff.

例如,假设您的路径是:

For example, let's say your path is:

.:/usr/bin

以便首先在当前目录中搜索命令,然后在 /usr/bin 中搜索.

so that commands will first be searched for in your current directory, then in /usr/bin.

然后另一个用户在他们的主目录中创建了一个可执行脚本文件 ls,该文件将更改为 您的 主目录并删除您的所有文件.然后他们告诉你他们的主目录中有一些有趣的东西.您运行 ls 以查看它们的内容,然后您的文件将被删除.都是因为它首先从您的 当前 目录运行 ls.

Then another user creates an executable script file ls in their home directory which changes to your home directory and deletes all your files. Then they tell you they've got something interesting in their home directory. You run ls to see what they have, and your files are deleted. All because it ran ls from your current directory first.

这是针对幼稚系统管理员的一种特别喜欢的攻击媒介.

This is a particular favorite attack vector against naive system admins.

老实说,在我的家用机器上,我不太担心,因为我是唯一的用户,而且我不容易下载我不信任的东西.因此,为了方便起见,我通常将 . 添加到我的路径中,但通常在末尾,这样它就不会妨碍我执行更常规的命令.

To be honest, on my home machines, I don't worry too much, since I'm the only user and I'm not prone to downloading stuff I don't trust. So I usually add . to my path for convenience, but usually at the end so it doesn't get in the way of my more regular commands.

这篇关于运行没有点斜线的脚本(Ubuntu vs Mac)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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