在linux中,如何在终端的任何目录中启动程序(ex.sublime文本)?

时间:2021-10-22 17:31:46

I want to do the following thing: In a terminal that is in any directory, type: "sublime a.txt" And sublime text will open a.txt in the current directory. I know i need to somehow write some script but how? One of my friends has done it once but i forgot.

我想做以下事情:在任何目录中的终端中,键入:“sublime a.txt”并且sublime文本将在当前目录中打开a.txt。我知道我需要以某种方式写一些脚本,但如何?我的一个朋友做过一次,但我忘记了。

3 个解决方案

#1


0  

Add the folder where you have sublime to your PATH. Assuming that is "$HOME/Sublime Text 2/" that might look like

将您拥有sublime的文件夹添加到PATH。假设这可能是“$ HOME / Sublime Text 2 /”

export PATH="$PATH:$HOME/Sublime Text 2"

and you might also need an alias

你可能还需要一个别名

alias sublime=sublime_text

#2


0  

First, you should know where the sublime text is. For example, /usr/bin. Edit the profile of the user

首先,您应该知道崇高文本的位置。例如,/ usr / bin。编辑用户的个人资料

 export PATH=$PATH:/usr/bin

Then, re-longin the user with - option (which will execute the profile.) Now this user can start the sublime text in any directory.

然后,使用 - 选项(将执行配置文件)重新使用用户。现在,此用户可以在任何目录中启动sublime文本。

#3


0  

1) When you write a Linux shell script ... the script will do the same kinds of things you'd do from the command line.

1)编写Linux shell脚本时...脚本将执行与命令行相同的操作。

For example, if you type "sublime a.txt", then your script would also contain "sublime a.txt". Or "sublime $1" (to "parameterize" argument #1).

例如,如果您键入“sublime a.txt”,那么您的脚本也将包含“sublime a.txt”。或“sublime $ 1”(参数化“参数化”#1)。

Here is a simple shell scripting tutorial (one of many you can easily find on the web): http://linuxconfig.org/bash-scripting-tutorial

这是一个简单的shell脚本编写教程(您可以在Web上轻松找到的许多教程之一):http://linuxconfig.org/bash-scripting-tutorial

2) The reason "it works from anywhere" ... is that the command "sublime" happens to be in your $PATH variable.

2)“它可以在任何地方工作”的原因......命令“sublime”碰巧出现在你的$ PATH变量中。

If "sublime" is installed in a "standard directory" (like "/usr/bin"), then you shouldn't need to change your $PATH - it should just work automatically.

如果“sublime”安装在“标准目录”(如“/ usr / bin”)中,那么您不需要更改$ PATH - 它应该自动运行。

3) If you successfully type "sublime a.txt" (or "subl a.txt") from a command line on one PC ... but the same command fails on a different PC ... then maybe sublime just isn't installed on the second PC.

3)如果您在一台PC上从命令行成功键入“sublime a.txt”(或“subl a.txt”)...但是同一命令在另一台PC上失败...那么可能只是sublime而不是安装在第二台PC上。

Here are instructions for installing on Fedora/RedHat/Centos (if that happens to be your OS:

以下是在Fedora / RedHat / Centos上安装的说明(如果这恰好是您的操作系统:

http://digitizor.com/2014/06/30/install-sublime-text-editor-3-fedora-redhat/

Otherwise, you should be able to install sublime with the standard tools "apt-get" or "yum".

否则,您应该能够使用标准工具“apt-get”或“yum”安装sublime。

#1


0  

Add the folder where you have sublime to your PATH. Assuming that is "$HOME/Sublime Text 2/" that might look like

将您拥有sublime的文件夹添加到PATH。假设这可能是“$ HOME / Sublime Text 2 /”

export PATH="$PATH:$HOME/Sublime Text 2"

and you might also need an alias

你可能还需要一个别名

alias sublime=sublime_text

#2


0  

First, you should know where the sublime text is. For example, /usr/bin. Edit the profile of the user

首先,您应该知道崇高文本的位置。例如,/ usr / bin。编辑用户的个人资料

 export PATH=$PATH:/usr/bin

Then, re-longin the user with - option (which will execute the profile.) Now this user can start the sublime text in any directory.

然后,使用 - 选项(将执行配置文件)重新使用用户。现在,此用户可以在任何目录中启动sublime文本。

#3


0  

1) When you write a Linux shell script ... the script will do the same kinds of things you'd do from the command line.

1)编写Linux shell脚本时...脚本将执行与命令行相同的操作。

For example, if you type "sublime a.txt", then your script would also contain "sublime a.txt". Or "sublime $1" (to "parameterize" argument #1).

例如,如果您键入“sublime a.txt”,那么您的脚本也将包含“sublime a.txt”。或“sublime $ 1”(参数化“参数化”#1)。

Here is a simple shell scripting tutorial (one of many you can easily find on the web): http://linuxconfig.org/bash-scripting-tutorial

这是一个简单的shell脚本编写教程(您可以在Web上轻松找到的许多教程之一):http://linuxconfig.org/bash-scripting-tutorial

2) The reason "it works from anywhere" ... is that the command "sublime" happens to be in your $PATH variable.

2)“它可以在任何地方工作”的原因......命令“sublime”碰巧出现在你的$ PATH变量中。

If "sublime" is installed in a "standard directory" (like "/usr/bin"), then you shouldn't need to change your $PATH - it should just work automatically.

如果“sublime”安装在“标准目录”(如“/ usr / bin”)中,那么您不需要更改$ PATH - 它应该自动运行。

3) If you successfully type "sublime a.txt" (or "subl a.txt") from a command line on one PC ... but the same command fails on a different PC ... then maybe sublime just isn't installed on the second PC.

3)如果您在一台PC上从命令行成功键入“sublime a.txt”(或“subl a.txt”)...但是同一命令在另一台PC上失败...那么可能只是sublime而不是安装在第二台PC上。

Here are instructions for installing on Fedora/RedHat/Centos (if that happens to be your OS:

以下是在Fedora / RedHat / Centos上安装的说明(如果这恰好是您的操作系统:

http://digitizor.com/2014/06/30/install-sublime-text-editor-3-fedora-redhat/

Otherwise, you should be able to install sublime with the standard tools "apt-get" or "yum".

否则,您应该能够使用标准工具“apt-get”或“yum”安装sublime。