Question: Unix/Lunix Programming Exercise 1 Read the following script read_validate and answer the questions. read -p Enter a single item > # is input a
Unix/Lunix Programming
Exercise 1
Read the following script read_validate and answer the questions.
read -p "Enter a single item > "
# is input a valid filename?
if [[ $REPLY =~ ^[-[:alnum:]\._]+$ ]]; then
echo "'$REPLY' is a valid filename."
if [[ -e $REPLY ]]; then
echo "And file '$REPLY' exists."
else
echo "However, file '$REPLY' does not exist."
fi
# is input a floating point number?
if [[ $REPLY =~ ^-?[[:digit:]]*\.[[:digit:]]+$ ]]; then
echo "'$REPLY' is a floating point number."
else
echo "'$REPLY' is not a floating point number."
fi
# is input an integer?
if [[ $REPLY =~ ^-?[[:digit:]]+$ ]]; then
echo "'$REPLY' is an integer."
else
echo "'$REPLY' is not an integer."
fi
else
echo "The string '$REPLY' is not a valid filename."
fi
What is the meaning of the command [[ "$REPLY" =~ ^[-[:alnum:]\._]+$ ]] ?
What is the meaning of the command [[ $REPLY =~ ^-?[[:digit:]]*\.[[:digit:]]+$ ]] ?
If the script is executed and a user provides --123.0 as the input, what shall be the output of the program?
If the script is executed and a user provides 0.0 as the input, what shall be the output of the program?
If the script is executed and a user provides -0. as the input, what shall be the output of the program?
If the script is executed and a user provides 012 as the input, what shall be the output of the program?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
