You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/bin/bash (called shebang) tells the system to use the bash shell to execute the script.
Variables are assigned using name=value (no spaces). You access them with $name.
Quotes:
Double quotes " " allow variable expansion.
Single quotes ' ' treat everything literally.
read gets user input.
select creates simple menus in bash scripts.
[ ], [[ ]], and test are used to evaluate conditions:
[ $a -eq $b ], [[ $a == $b ]], or test $a -eq $b
Commands Practiced
# Start a basic script#!/bin/bashecho"Hello, Linux!"# Set and print a variable
username="stark"echo"Hi, $username"# User input using readread -p "Enter your age: " age
echo"You are $age years old"# Conditional if-elseif [ $age-ge 18 ];thenecho"Adult"elif [ $age-eq 17 ];thenecho"Almost there!"elseecho"Minor"fi# Using test commandiftest$age -gt 0;thenecho"Valid age"fi# Using select to create a simple menuselectoptionin Start Stop Exit;doecho"You selected $option"breakdone