Professional Documents
Culture Documents
Sample Shell Programs
Sample Shell Programs
Sample Shell Programs
/bin/bash
1. Hello world
# Hello World!
echo "Hello World!"
2. User Ip & op
echo "Enter your name:"
read username
echo "Hello, $username!"
3. Conditional (if-else)
echo "Enter a number:"
read number
5. Function
say_hello() {
echo "Hello from a function!"
}
say_hello
6. Command substitution
current_date=$(date)
echo "Current date: $current_date"
7. Arithmetic operations
num1=5
num2=3
sum=$((num1 + num2))
echo "Sum: $sum"
8. Arrays
fruits=("Apple" "Banana" "Orange")
echo "First fruit: ${fruits[0]}"
if [ -e "$filename" ]; then
echo "$filename exists."
else
echo "$filename does not exist."
fi