Linux 如何在 ubuntu 中打开 .sh 扩展名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7592160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:25:11  来源:igfitidea点击:

how to open up .sh extension in ubuntu

linux

提问by Hold_My_Anger

I am a window user,and never tried Linux before. Because of project, I installed the Ubuntu and I downloaded one file in .sh extension. That file is the python from Enthough Distribution. I tried to double clicked the .sh file and there is error. I really have no idea how Linux works. I searched in Google but they showed some command lines that I don't understand. So I hope somebody can provide some detailed guide. Sorry I am a total Linux newbie.

我是一个窗口用户,以前从未尝试过 Linux。由于项目原因,我安装了 Ubuntu 并下载了一个扩展名为 .sh 的文件。该文件是来自 Enthough Distribution 的 python。我试图双击 .sh 文件,但出现错误。我真的不知道 Linux 是如何工作的。我在谷歌搜索,但他们显示了一些我不明白的命令行。所以我希望有人可以提供一些详细的指南。对不起,我是一个 Linux 新手。

Here is a picture of the error: enter image description here

这是错误的图片: 在此处输入图片说明

采纳答案by talnicolas

Just open a terminal (should be somewhere in your application menu), go to the directory where the .shfile is (command is cd /the/paththen Enter) and type:

只需打开一个终端(应该在您的应用程序菜单中的某个位置),转到.sh文件所在的目录(命令是cd /the/paththen Enter)并键入:

sh yourfile.sh

or

或者

./yourfile.sh

then Enter.

然后Enter

回答by Aquertu

You should be able to open it normally with gedit all it is is text its not a binary or anything the only reason I can think of would be if that wasnt the actual file type I'd be wary of using that. .sh is well you could say the equivalent of .bat on windows its pure text so it should open normally that is unless its a binary,picture,or mp3.

你应该能够用 gedit 正常打开它,它是文本,它不是二进制文件或任何我能想到的唯一原因是,如果那不是我会谨慎使用它的实际文件类型。.sh 很好,你可以说 Windows 上的 .bat 相当于它的纯文本,所以它应该正常打开,除非它是二进制、图片或 mp3。

回答by selegnasol

Don't forget to change permissions of that file unless you have done already.

除非您已经完成,否则不要忘记更改该文件的权限。

  • In ubuntu terminal type: sudo -i. Now, you're root!
  • Go to the folder with this file (cdcommand).
  • Do man chmodcommand (change file mode bits). Check permissions of that file:

    root:/folder_with_sh_file# ls -l | grep 'filename'

  • 在 ubuntu 终端输入:sudo -i. 现在,你是根!
  • 转到包含此文件的文件夹(cd命令)。
  • 执行man chmod命令(更改文件模式位)。检查该文件的权限:

    根目录:/folder_with_sh_file# ls -l | grep '文件名'

If the file is not executable(x), you will have to run this command:

如果该文件不可执行 (x),则必须运行以下命令:

root:/folder_with_sh_file# chmod 755 ./filename.sh

NB: you can also use 777. 4 - read, 2 - write, 1 - execute. If you SUM together, it all works out.

注意:您也可以使用 777。4 - 读取,2 - 写入,1 - 执行。如果你SUM在一起,一切都会好起来的。

回答by Alex

use vim 'filename'for opening the file to read/modify it in a cli (command line interface / shell) or use gedit 'filename'to read/modify it in a graphical interface.

使用vim 'filename'用于打开文件的读取/修改它在CLI(命令行接口/ shell)或使用gedit 'filename'读/修改它在图形界面。

if you have no permissions to do so, checkout man chownerto change the onwer of the file and man chmodfor file permissions. You might need to use sudo 'command'in some cases, the sudocommand allows you to run programs with the security privileges of another user (normally the superuser, or root).

如果您没有权限这样做,请检查man chowner以更改文件的名称和man chmod文件权限。sudo 'command'在某些情况下您可能需要使用,该sudo命令允许您以另一个用户(通常是超级用户或 root)的安全权限运行程序。

Check this link out to get some really basic linux knowledge: https://help.ubuntu.com/community/Beginners/BashScripting

查看此链接以获得一些非常基本的 linux 知识:https: //help.ubuntu.com/community/Beginners/BashScripting

回答by Akash Kandpal

If no permissoin issues then use this in terminal :

如果没有许可问题,则在终端中使用它:

Run bash <filename>.sh

else if permission issues are there then follow this :

否则,如果存在权限问题,请按照以下步骤操作:

Give execute permission to your script:

为您的脚本授予执行权限:

chmod +x /path/to/filename.sh

And to run your file:

并运行您的文件:

/path/to/filename.sh

Since . refers to the current directory: if filename.sh is in the current directory, you can simplify this to:

自从 。指当前目录:如果filename.sh在当前目录下,可以简化为:

./filename.sh