Bash Scripting Guide: From Basic to Advanced
===========================================
Step 1: Setup
-------------
Open Terminal and create a folder for practice:
mkdir bash_practice && cd bash_practice
Step 2: Your First Script
--------------------------
Create a file:
nano [Link]
Add:
#!/bin/bash
echo "Hello, World!"
Make executable:
chmod +x [Link]
Run:
./[Link]
Explanation:
- #!/bin/bash · Shebang, tells system to use Bash.
- echo · Prints text.
- chmod +x · Makes script executable.
Step 3: Variables
-----------------
#!/bin/bash
name="Bhanu"
echo "Hello $name"
Explanation:
- Variables store data.
- $name · Access variable.
Step 4: User Input
------------------
#!/bin/bash
read -p "Enter your name: " username
echo "Welcome $username"
Explanation:
- read · Takes input.
- -p · Prompt message.
Step 5: Conditions
------------------
#!/bin/bash
if [ $1 -gt 10 ]; then
echo "Number is greater than 10"
else
echo "Number is less or equal to 10"
fi
Run:
./[Link] 15