As with any Programming or Scripting Language, let us take a look at the very basic two lines script called "Hello World!" in Bash!
The best way to learn and write Shell Scripts is by making use of editors like vi or nano, in this example, we will make use of nano,
Step by Step Hello World! Bash Scripting Example
- Open Terminal,
- Type nano helloWorld.sh and press enter, this will open Nano Editor for you,
- Write the below code,
#!/bin/bash echo Hello World!
- Press Control + X and then Y to save.
- Now run command chmod +x helloWorld.sh just to make sure we can execute this script,
- Type ./helloWorld.sh
![Result of running bash hello world script Result of running bash hello world script](https://code2care.org/tutorial/bash-hello-world-script-tutorial/images/Result of running bash hello world script.png)
Congratulations! You ran you first bash script successfully!
More Posts related to Bash,
- How to use Autocomplete and Autosuggestion in Shell Commands
- Bash How to Save Output of a Command to a Variable
- How to know the current shell you are logged in?
- How to Echo Bash Command to a File
- Bash Command to Get Absolute Path for a File
- How to Split a String based on Delimiter in Bash Scripting
- Bash: Command Line Arguments to Bash Script Examples
- Bash Command to Download a File From URL
- How to check if a Command Exists using Bash Script
- Ways to Increment a counter variable in Bash Script
- Know Bash shell version command
- Bash command to Read, Output and Manipulate JSON File
- Bash Command to Base64 Decode a String
- Bash Command to Check Python Version
- Bash: Command to Find the Length of a String
- What is $$ in Bash Shell Script- Special Variable
- Bash - How to check if a Command Failed?
- List all Username and User ID using Bash Command
- Command to Sort File In Reverse Order [Unix/Linux/macOS]
- bash: netstat: command not found
- Bash Command To Go Back To Previous Directory
- [Fix] bash: script.sh: /bin/bash^M: bad interpreter: No such file or directory
- How to check your IP using bash for Windows?
- Bash Command To Check If File Exists
- Convert String from uppercase to lowercase in Bash
More Posts:
- Change Google Chrome Browsers default download location - Chrome
- [Nopepad++] How to add text at end of each line - NotepadPlusPlus
- Android Studio : Connection Error : Failed to download patch file - Android-Studio
- How to Delete a Sheet in Excel on Mac - Microsoft
- Remove Apps from Dock when Quit [Mac Ventura] - MacOS
- Create a Zip file using Java Code programmatically - Java
- Fetch as Google Crawl Error or Redirected Status - Google
- AWS S3 CLI BucketAlreadyExists when calling CreateBucket Error make_bucket failed - AWS