Files
hpr_website/www/eps/hpr2679/hpr2679_bash13_ex1.sh

24 lines
370 B
Bash
Executable File

#!/bin/bash
#
# Three word regular expression
#
re='^([a-zA-Z]+) +([a-zA-Z]+) +([a-zA-Z]+) *\.?'
#
# A sentence is expected as the only argument
#
if [[ $# -ne 1 ]]; then
echo "Usage: $0 sentence"
exit 1
fi
echo "Sentence: $1"
if [[ $1 =~ $re ]]; then
echo "Matched"
for i in {0..3}; do
printf '%2d %s\n' $i "${BASH_REMATCH[$i]}"
done
fi