How to write a Bash script
Help 2 / 9
Your first script

Hello world

Let’s start out with a “simple” example. In the code editor on your right, you’ll find the script hello.sh, which outputs Hello world to the screen.

The more detail-oriented among you may have noticed the quotes around the word “simple”, and you’d be right to think something’s up because this script doesn’t run!

Try it yourself:

./hello.sh

You’ll see a Permission denied error, but don’t worry, this is an error most of us run into, even after years of using the command line.

It happens because when you create a new file in Linux, you only have permissions to read (r) and write (w) it, but not execute (x) it.

For that, you need to explicitly grant yourself (u) permission to do so:

chmod u+x hello.sh

Then run the script again:

./hello.sh

Now it’s working as expected!

Loading...