#!/bin/bash

# Besides using =, there are two other main methods to assign values to
# variables.
# One is the 'read' command, which reads from stdin or from a file
# descriptor.

# Using a prompt
read -p "Enter a digit: " MY_DIGIT
echo ${MY_DIGIT}

# Do not echo input coming from a terminal
read -p "Enter a secret word: " -s SECRET

# Time out (-t) after T seconds (default: $TMOUT)
read -t 5 -p "Yes or no? You have 5 s to respond: " YESNO

# Read from a file descriptor (-u).

file="testfile.txt"
echo "This is the first line of the file." > "$file"
echo "This is the second line of the file" >> "$file"
exec 3<"$file"
read -r -u 3 LINE
echo "First line read: $LINE"
read -r -u 3 LINE
echo "Second line read: $LINE"
exec 3<&-
rm "$file"

# More options; see man page.

