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.
STDIN
– Archemar Mar 27 '19 at 05:56/
. You just need to escape the spaces.sed
is unlikely to know what\w
is (macOSsed
does not know PCRE expressions). Instead, use[[:alnum:]_]
(this is a POSIX character class equivalent to\w
). – Kusalananda Mar 27 '19 at 06:50