Bash is the default shell for most GNU/Linux distributions and essential for automating tasks and system administration.
Basic script structure
#!/usr/bin/bash
The shebang #!/usr/bin/bash
tells the system which interpreter to use.
Variables
greeting=Hello
name=Sanatan
No spaces around the =
sign when assigning variables.
Arithmetic operations
sum=
Operators: +
(addition), -
(subtraction), *
(multiplication), /
(division), **
(exponential), %
(modulo)
Calculator with decimals
|
Use bc
command for floating-point calculations. scale
sets decimal places.
User input
sum=
Conditional statements
Comparison operators:
-eq
: equal-ne
: not equal-gt
: greater than-ge
: greater than or equal-lt
: less than-le
: less than or equal
if [
then
fi
if [
then
elif [
then
else
fi
Loops
for
do
done
counter=1
while [
do
done
Functions
# Call the function
File permissions
Make your script executable:
Bash scripting is fundamental for Linux automation and system management tasks.