简体   繁体   English

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

[英]Having trouble writing my first bash script

ok I am writing my first bash script in ubuntu 10.04. 好的我正在ubuntu 10.04中编写我的第一个bash脚本。

The file is on my desktop: /home/myuser/Desktop 该文件位于我的桌面上: /home/myuser/Desktop

The file is called hello-world 该文件称为hello-world

The file contains: 该文件包含:

#!/bin/bash
echo "Hello World"

I open a command line and run: 我打开一个命令行并运行:

/home/myuser/Desktop/hello-world /家/ myuser的/桌面/你好世界

It tells me permition is denied. 它告诉我permition被否定了。 So I run it again with sudo, it asks me for my password, I type it in, hit return. 所以我用sudo再次运行它,它询问我的密码,我输入,点击返回。

I get this output. 我得到了这个输出。

sudo: /home/myuser/Desktop/hello-world: command not found sudo:/ home / myuser / Desktop / hello-world:找不到命令

What am I doing wrong? 我究竟做错了什么?

Your script probably is not set to be executable. 您的脚本可能未设置为可执行文件。 Try: 尝试:

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

If your script is called test.sh then do the following... 如果您的脚本名为test.sh,请执行以下操作...

$ chmod +x test.sh

followed by 其次是

$ ./test.sh

chmod +x hello-world

You need to mark the script as executable. 您需要将脚本标记为可执行文件。 Run chmod +x hello-world to add the executable bit. 运行chmod +x hello-world添加可执行位。

You can also do: 你也可以这样做:

sh /home/myuser/Desktop/hello-world

which will execute the script without it needing to be set as executable. 这将执行脚本,而不需要将其设置为可执行文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM