Getting Started with Shell Scripts on Linux (Bash Basics)

Getting Started with Shell Scripts on Linux (Bash Basics)

Before you know shell scripting, every little task in Linux feels manual.
You type the same commands again and again, mistype one, redo it, and lose a few more minutes of your life.
After you pick up basic shell scripting, you put those commands in a file, give it a name, and run it with one line.
Simple, repeatable, and much harder to mess up.

This guide is for you if you’re new to Linux, new to Bash, or you’ve only typed commands directly into the terminal and never saved them as a script.
We’ll keep it basic and practical: what a shell is, how to check which shell you’re using, then how to create, give permission to, and run a simple Bash script.


What Is a Shell (and Why You Should Care)

Shell is a command interpreter program that acts as the user interface between you and the kernel (the core of the operating system).
In plain words: you type commands in the shell, the shell passes them to the kernel, and you get the result.

On Linux, there are several shells, for example:
– Bourne shell (sh)
– C shell (csh)
– Korn shell (ksh)
– Bourne again shell (bash)

All major operating systems have some kind of shell: Windows, Mac OS, and Unix/Linux.
But on many Linux systems (including Ubuntu), the default shell is usually bash.

For scripting, that matters.
Your script will be interpreted by whatever shell is set, so you want to know what you’re working with.


Step 1 — Check Which Shell You’re Using

On Ubuntu (and many other distributions), the default shell is Bash.
To confirm what your default shell is, you can run the shell-checking command described in the original article.

Open your terminal and type the check command.
You’ll see an output showing which shell is set as your default, for example something pointing to bash.

Why this matters: when you write a shell script, you need to know which shell is interpreting your commands, because syntax and features can differ between shells.
If you expect Bash features but your script runs with a different shell, you can hit weird errors.


Step 2 — Understand Where Commands Live

When you type commands in the shell, there are two big categories:

  1. Internal shell commands – Built into the shell itself (things like cd in many shells).
  2. External commands – Actual executable files outside the shell (programs installed on the system).

Shell scripts can contain both types of commands.
That’s why the original author suggests you first learn basic shell commands: your script is basically a saved list of those commands.

So before going deeper with scripting, get comfortable running simple commands in the terminal.
That way, when you put them in a script file, you already know what they’re supposed to do.


Step 3 — Create Your First Shell Script File

To create a shell script, you just create a normal text file.
You can use any text editor you like in the terminal.
The source mentions:

  • vi / vim
  • nano
  • gedit (graphical editor)

For example, the first sample script in the source shows a basic program that displays text:

The example prints the text: sebarkan walau sebaris kode.

That file is saved with the name shell-echo.

So the basic process is:

  1. Open your editor.
  2. Type a command that prints your message.
  3. Save the file with a name, like shell-echo.

At this stage, the file is just a plain text file.
It’s not yet executable.

Safety note:
Create and test your first scripts inside your home directory (for example, in a folder like scripts/).
Avoid editing or creating scripts as root unless you really need to.
Mistakes as root can break your system quickly.


Step 4 — Make the Script Executable (Permissions)

Linux won’t execute a plain text file as a program unless it has execute permissions.
So after you create the script file (like shell-echo), you need to set its permissions so it can be run.

The source explains that:

The created file must have its access rights set so it can be executed.

This is the missing step many beginners trip over.
You create a script, try to run it, and get a “Permission denied” error.
Giving it execute permission solves that.

Permissions are important for safety:
– You don’t want every script writable and executable by everyone.
– Keep your scripts executable by you, and only writable by you.

For personal scripts in your home directory, keep ownership and permissions tight.
Don’t casually set scripts to be world-writable or world-executable unless you know why.


Step 5 — Run Your Shell Script

After adding execute permission, you can finally run the script.
The article shows that after setting execute permissions, you use the execution method it describes to run the script.

This is the point where it feels satisfying.
Instead of typing a command manually each time, you just run your script file and let it do the work.

The example idea from the article is simple but useful:

A first program prints the text sebarkan walau sebaris kode when executed.

You can swap that text with anything you like.
For example, a quick reminder note, a project banner, or a startup message you like to see.

Safety tip:
Before running scripts from other people, open the file in your text editor and read every line.
Never blindly run scripts with elevated privileges.


Step 6 — Add Simple Shell Commands to Your Script

Once the basic “print text” script works, you can start adding more shell commands.
The source shows an example idea:

Clear the terminal screen first, then display the text.

So the script’s flow is:
1. Clear the screen.
2. Print the message.

This is exactly how shell scripting works: take the commands you already type one-by-one, and put them in a file in the order you want them executed.

Some ideas you can use based on that pattern:

  • Clear the screen, then show a message.
  • Show a few lines of information in a row.
  • Run a sequence of commands you often type manually.

Again, don’t overthink it in the beginning.
Start by automating very small, boring things, then grow from there.


Where to Go After This (Bash Script Series)

The original article is part of a bigger series about Bash scripting, broken into seven parts:

  1. Shell Script on Linux
  2. Variables
  3. Array
  4. Input Output
  5. Selection
  6. Looping
  7. Functions

What you’ve just done here is the first part: getting to know what a shell is and how to write and run a simple script.
From there, you can move on to variables, arrays, input/output, conditions, loops, and functions.

Each of those lets you do more powerful automation:
– Variables let you store values.
– Arrays let you store lists.
– Input/output lets your script interact.
– Selection and looping let your script make decisions and repeat actions.
– Functions help you reuse parts of your script.

But it all starts with this simple step: a text file with shell commands, made executable, and run from your terminal.


If this worked for you, keep CrushEdge handy for the next fix.

No Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.