I'm trying to pass the output of an awk command as a variable in a bash script, but not having much success so any help is appreciated.
homedirectory=$(awk /stephen/ /etc/passwd | awk -F/home/ '{print $2}' | awk -F/downloads '{print $1}')
echo '$homedirectory'
I want to extract the home directory of user stephen from the /etc/passwd, so the result I want is 0001
/etc/passwd
statd:x:102:65534::/var/lib/nfs:/bin/false
bind:x:103:106::/var/cache/bind:/bin/false
sshd:x:104:65534::/var/run/sshd:/usr/sbin/nologin
mysql:x:105:107:MySQL Server,,,:/var/lib/mysql:/bin/false
messagebus:x:106:108::/var/run/dbus:/bin/false
stephen:x:1039:1031::/home/0001/downloads:/bin/false