First Shell Script
Open up your favorite text editor.
You can use any text editor to write the shell scripts.
Normally the shell scripts has the file extension .sh
In our example programs we will be saving the files with .sh extension.
firstshellscript.sh
The first line of every SHELL script is a commented line directed toward the interpreter.
firstshellscript.sh:
#!/bin/bash
Try the command: which bash
Use this location for your shell scripts.
Lets start with a simple script to print " Hello World "
Example:
#!/bin/bash echo "Hello World"
Save it as " firstshellscript.sh ".
You will need to give execute permissions for your scripts.
Examples:
$ chmod +x firstshellscript.sh
or
$ chmod 755 firstshellscript.sh
Now how to run your script?
There are 3 different ways to run a shell script:
1. bash firstshellscript.sh
2. sh firstshellscript.sh
3. ./firstshellscript.sh
Try all the above.
In our examples we will be using any of these options.
Related posts:
- Shell Scripting Introduction
- Shell Syntax
- Shell - Strings
- Shell - Variables
- Shell - User Intraction
- First Shell Script
- Shell - Arithmetics
- Shell - Case Statement
- Shell - Command Line Arguments
- Shell - For Loop
- Shell - While Loops
- Shell - IF Statements
- Shell - Input Output Redirections
- Shell - Pipes and Filters
- Shell - Process Management
Your IP address1 is: 172.18.0.2
Tutorials
Latest Updates
Follow us
- Tech-Tutorials twitter.com/techcuriosity