2010-06-18 40 views
2

好的我在ubuntu 10.04中编写我的第一个bash脚本。编写我的第一个bash脚本时遇到问题

该文件是我的桌面上:/home/myuser/Desktop

该文件称为hello-world

该文件包含:

#!/bin/bash 
echo "Hello World" 

我打开一个命令行并运行:

/home/myuser/Desktop/hello-world

它告诉我的授权被拒绝。所以我用sudo再次运行它,它要求我输入密码,然后输入,然后回车。

我得到这个输出。

须藤: /家/ myuser的/桌面/你好世界: 找不到命令

我在做什么错?

回答

2

chmod +x hello-world

+0

谢谢! ......(填充文本) – 2010-06-18 19:01:36

4

您的脚本可能未设置为可执行文件。尝试:

chmod u+x /home/myuser/Desktop/hello-world 
2

您需要将脚本标记为可执行文件。运行chmod +x hello-world添加可执行位。

1

你也可以这样做:

sh /home/myuser/Desktop/hello-world 

将执行脚本没有它需要被设置为可执行。

+3

不应该是'bash/home/myuser/Desktop/hello-world'来符合OP的shell选择吗? – 2010-06-18 19:21:19

3

如果你的脚本被称为test.sh然后执行以下操作...

$ chmod +x test.sh

其次

$ ./test.sh