sh Variable Handling
Arrays
Arrays
ARRAY=('VAR1' 'VAR2')
for ROW in ${ARRAY[@]}
do
echo ${ROW}
done
Referencing the array index instead of the array variables...
ARRAY=('VAR1' 'VAR2')
for ROW in ${!ARRAY[@]}
do
echo ${ROW}
done
Populating an array from a file...
IFS=$'\r\n' GLOBIGNORE='*' command eval 'ARRAY=($(cat /tmp/$$.txt))'
echo "${ARRAY[1]}"
or (bash 4+)...
readarray -t ARRAY < /tmp/$$.txt
Read
Read
read myvar
read -p "Enter your password" myvar
read -p "Enter your password" -s myvar
Read variable from stdin
Prompt for entry
Prompt for entry, hide what is typed
Output
Output
echo myvar
echo ${myvar}
printf "%s\n" "${myvar}"
Bibliography
Bibliography