I used following piece of code to list down the contents of a directory in macOS:
#!/bin/bash
echo "hello User"
echo ""
userdir=$1
var_one=$userdir\/Library\/Application\ Support\/iCloud\/Accounts\/
if [ -d "$var_one" ]
then
# echo "Direcotry exists"
echo "The AppleID is : "
sed -n '/[*\w-]+@([\w-]+\.)+[\w-]+/p'|ls "$var_one"|awk NR==2'{print}'
echo "~~~~~~~BYE~~~~~~"
break
else
echo "Directory doesn't exists"
echo "The path is $var_one"
fi
If the directory exists then sed command is used along with regex pattern to identify the desired file. The script works fine but doesn't seem to exit.