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
# For loopforiin 1 2 3 4 5;doecho"$i"done# Rangeforiin {1..10};doecho"$i"done# C-stylefor((i=0; i<10; i++));doecho"$i"done# Loop over filesforfilein*.py;doecho"Processing $file"done# While loop
count=0
while [[ $count-lt 5 ]];doecho"$count"((count++))done# Read file line by linewhile IFS= read -r line;doecho"$line"done< file.txt
Functions
# Definegreet() {
local name="$1"# local scopeecho"Hello $name"
}
# Call
greet "Daniel"# Return values (exit codes)is_even() {
if(($1%2==0));thenreturn 0 # success/trueelsereturn 1 # failure/falsefi
}
if is_even 4;thenecho"even"fi# Return strings via stdoutget_date() {
date +%Y-%m-%d
}
today=$(get_date)
Arguments
# In a script or function:$0# Script name$1# First argument$2# Second argument$## Number of arguments$@# All arguments (as separate words)$*# All arguments (as one word)$?# Exit code of last command$$# Current process ID