DEV Community

Cover image for Write your first shell script

Posted on


Write your first shell script

The Shell is a layer between the Operating System(OS) and the user.🐚 It is a user interface for access to the operating system and it uses either a command-line interface (CLI) or a graphical user interface (GUI). In Linux and MacOS this CLI is called Terminal, in Windows Command Prompt.

You can write scripts for the shell which can be used for various purposes, such as executing a shell command, running multiple commands together or performing task automation.

It's easy to get started with shell scripting, let`s create a β€œhello world” shell script for Linux:

  1. Open an editor and write: #!/bin/bash echo "Hello World"
  2. Save it with a name of your choice with .sh at the end. (I chose β€œ”)
  3. Open your Terminal at the path where you saved the file.
  4. Execute chmod +x to make the file executable.
  5. Execute β€œ./”

Thats it! What are you up to today? Anything you want to share about the Shell? Have a nice day!😊

Top comments (4)

mccurcio profile image
Matt Curcio

One of the first Bash commands I learned was rm -fr . Not good, but good to know!
It seemed like people everywhere I turned were trying to trick others into using this dangerous command.
I never got caught by this or other commands bc others let me in on the 'secret'. ;))

anja profile image

Hehe good that you didn't fall into the trap! My first command was cd. πŸ˜„

stevezieglerva profile image
Steve Ziegler

Life gets a lot better when you learn to script boring and repetitive things!

anja profile image

Yes I totally agree! 😊 Let's automate things to have time for the interesting things. πŸ‘©β€πŸ’»

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.