Se o seu problema estiver limitado a essas duas opções, algo assim:
usage() {
echo "tools.sh -id <id> -f <file>"
echo "note: order of options is not important"
}
if [ $# -ne 4 ]; then
echo "Wrong number of arguments"
usage
exit 1
fi
if [ "$1" = "-f" -a "$3" = "-id" ]; then
file="$2"
id="$4"
elif [ "$1" = "-id" -a "$3" = "-f" ]
then
file="$4"
id="$2"
else
echo "Wrong syntax!"
usage
exit 1
fi
Depois, você pode analisar seu arquivo com o awk:
awk -F'|' -v id="$id" '$1==id{printf "ID: "$1"\nUser: "$2" "$3"\nGender: "$4"\nBorn: "$5"\nCreation Date: "$6"\nLocation IP: "$7"\nBrowser used: "$8"\n"}' $file
if [ $? -eq 0 ]
then
exit 0
else
echo "Something went \"woopsie!\""
exit 1
fi
Para melhorar, você também pode verificar se id
é um número e que persons.dat
é realmente um arquivo em algum lugar em PATH
...