从当前目录中执行不带“ ./filename”的Shell脚本。 [英] Executing Shell Script from current directory without '"./filename"

查看:137
本文介绍了从当前目录中执行不带“ ./filename”的Shell脚本。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个名为 testfile的文件,并使用 chmod + x testfile 使它可执行。
为了执行文件 testfile,我需要运行命令 ./ testfile

I have created a file called "testfile" and made it executable using chmod +x testfile. In order to execute the file "testfile" i need to run the command ./testfile.

我需要知道有什么方法可以不使用来运行程序。/并使用 testfile 执行文件

I need to know is there any way i could run the program without using ./ and execute the file using testfile command?

下面显示的是文件 testfile中的简单代码

Shown below is a simple code inside the file "testfile"

echo Todays date is : 
date


推荐答案

您可以使用。

sh testfile

sh /path/to/file/testfile

编辑

如果要执行直接使用命令在程序中执行操作,您可以定义一个别名:

Edit
If you want to execute the program directly with a command, what you can do is to define an alias:

alias execute_testfile="sh /path/to/file/testfile"

然后,只要编写,就会执行程序

And then, you will execute the program whenever you write

execute_testfile

或您定义的任何名称。

到使此别名永久存在,请在您的〜/ .profile或〜/ .bash_profile文件中包含 alias ... 行。

To make this alias persistent, do include the alias ... line in your ~/.profile or ~/.bash_profile files.

这篇关于从当前目录中执行不带“ ./filename”的Shell脚本。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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