Open In App

.sh | File Format

A .sh file is a scripting language command file containing a computer program that can be run by the Unix shell. It can contain a series of commands that run sequentially to perform operations such as file processing, program execution, and other similar tasks. These are run from the command line interface by the user or in batch mode to perform multiple operations simultaneously. Script files can be opened in text editors such as Notepad, Notepad++, Vim, Apple Terminal, and other similar applications on Windows, MacOS, and Linux.

Brief History

The .sh file extension is often associated with shell scripts, particularly those written for Unix-like operating systems. It originated with the development of Unix in the early 1970s. Stephen Bourne developed the original Unix shell, known as the Bourne Shell (sh). It became the default shell on Unix systems and included a scripting language for automating tasks. Users can begin creating shell scripts by writing a series of shell commands in a text file. It is still a fundamental component of Unix-like operating systems and is used extensively for a variety of scripting tasks, including automation and system administration. On many systems, Bash has emerged as the factory standard for shell scripting.



Here are some key points about shell scripts and .sh files:

SH File Format

Here’s a simple example 1 of a Bash script:

/* #!/bin/bash

echo “Hello, World!”



# Other commands can go here */

How to run the .sh file

To run this script, you would save it to a file, make it executable (chmod +x script.sh), and then execute it (./script.sh).

Output of the following code

Hello, World!

Example 2

/* #!/bin/bash

# This is a simple Bash script

# Prompt the user for their name

echo “Hello! What’s your name?”

read name

# Print a personalised greeting

echo “Nice to meet you, $name!” */

Save this code in a file with a .sh extension, for example, greeting.sh. To make it executable, run the following command in the terminal:

/* chmod +x greeting.sh */

Now you can execute the script:

/* ./greeting.sh */

Output

Hello! What’s your name?

John

Nice to meet you, John!

Conclusion

At last, we can say that shell scripting languages are widely used by developers when they are working directly with the operating system using the command line tools. That will help you to automate the many tasks that otherwise require human input which will increase the resource cost.

Article Tags :