LESSON · 1 OF 4

What is a shell script

What is a shell script

A shell script is a plain text file that holds a series of shell commands, meant to be run as a single program. Every line is something you could have typed at the prompt yourself, glued together into a reusable unit.

The point is repeatability. Any command sequence you'd type more than once eventually becomes a script.

The shape of a script

bash
#!/bin/bash
echo "hello, DevOps"

Two things worth noticing:

  • The first line, starting with #!, is the shebang. It tells Linux which interpreter to use for this file. #!/bin/bash says "run this with bash."
  • Every other # starts a comment. The shell ignores anything from # to the end of that line.

File extension is convention only

Scripts are usually named something.sh, but the .sh extension is decorative. Linux doesn't care about the extension, it cares about the shebang and whether the file is executable. You could name your script deploy (no extension) and it would work identically.

That's the whole reality: a shell script is a text file with a shebang that Linux is allowed to run.

Spin up a fresh environment and practice live.
linux-devops-basic · fresh machine · ready in under a minute