编写我的第一个bash脚本时遇到问题

时间:2010-06-18 18:57:33

标签: linux bash

好的我正在ubuntu 10.04中编写我的第一个bash脚本。

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

该文件名为hello-world

该文件包含:

#!/bin/bash
echo "Hello World"

我打开命令行并运行:

  

/首页/ myuser的/桌面/你好世界

它告诉我permition被拒绝。所以我用sudo再次运行它,它要求我输入密码,我输入密码,点击返回。

我得到了这个输出。

  

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

我做错了什么?

5 个答案:

答案 0 :(得分:4)

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

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

答案 1 :(得分:3)

如果您的脚本名为test.sh,请执行以下操作...

$ chmod +x test.sh

接着是

$ ./test.sh

答案 2 :(得分:2)

chmod +x hello-world

答案 3 :(得分:2)

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

答案 4 :(得分:1)

你也可以这样做:

sh /home/myuser/Desktop/hello-world

将执行脚本而不需要将其设置为可执行文件。

相关问题