Bash 脚本未运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29230778/
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
Bash script not running
提问by RohanK
I am trying to learn bash scripting and I'm using Ubuntu Linux. I have written a simple Bash file to count the number of files in current directory. I have written the following script in a file:
我正在尝试学习 bash 脚本,我正在使用 Ubuntu Linux。我编写了一个简单的 Bash 文件来计算当前目录中的文件数。我在文件中编写了以下脚本:
#! /bin/bash
ls -1 | wc -l
And saved the file with the name countFile
.
并使用名称保存文件countFile
。
But when I am trying to execute the script using ./countFile
it is not executing. It shows the following error:
但是当我尝试使用./countFile
它执行脚本时,它没有执行。它显示以下错误:
bash: ./countFile: Permission denied
The countFile
is in my home directory so why I haven't the permission. Am I doing something wrong or missing some important thing? Moreover, the ls -1 | wc -l
command gives me the correct output when I run it from the terminal.
So how can I run the countFile
script?
这countFile
是在我的主目录中,所以为什么我没有权限。我做错了什么或错过了一些重要的事情吗?此外,ls -1 | wc -l
当我从终端运行它时,该命令为我提供了正确的输出。
那么如何运行countFile
脚本呢?
回答by Karthikeyan.R.S
While you are giving like this,
当你像这样给予时,
./countfile
You have to make that file as executable using chmod
.
您必须使用chmod
.
chmod +x countfile
Or else you can use the other interpreter like this.
否则,您可以像这样使用其他解释器。
sh countfile
回答by Bhuvanesh
while executing the file we need a execute permission for that file, we can change the permission or we just run as
在执行文件时,我们需要该文件的执行权限,我们可以更改权限,或者我们只是运行
. countfile
hew .
will represent the current working shell
hew.
将代表当前工作的 shell