Trusted answers to developer questions

What is a Bash script?

Get Started With Data Science

Learn the fundamentals of Data Science with this free course. Future-proof your career by adding Data Science skills to your toolkit — or prepare to land a job in AI, Machine Learning, or Data Analysis.

Bash is a type of interpreter that processes shell commands. A command is given in the form of plain text that calls operating system services to perform a task.

Commands like ls or cd are frequently used by programmers; these commands are written in the terminal. The terminal acts as an interface for the shell interpreter.

A Bash script is a text file containing a series of commands.

Any command that can be executed in the terminal can be put into a Bash script. Any series of commands to be executed in the terminal can be written in a text file, in that order, as a Bash script.

Bash scripts are given an extension of .sh.

Let’s just say we have a Bash script, bash_intro.sh, consisting of the following commands:

cd DRP/
ls

In order to run the above Bash script, run the following command in the terminal:

bash bash_intro.sh

The shell will start executing the commands in the script in sequence; it will navigate to the DRP folder and then list its contents down in the terminal. See the output below:

RELATED TAGS

bash
script
operating system
commands
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?