DEV Community

Cover image for Write your first shell script
Anja
Anja

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 β€œhello.sh”)
  3. Open your Terminal at the path where you saved the file.
  4. Execute chmod +x hello.sh to make the file executable.
  5. Execute β€œ./hello.sh”

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

Top comments (4)

Collapse
 
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'. ;))

Collapse
 
anja profile image
Anja

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

Collapse
 
stevezieglerva profile image
Steve Ziegler

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

Collapse
 
anja profile image
Anja

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