I need to copy /root/nbu/file1.sh
to every user's home directory if user's id is even number.
Trying to execute following script:
#!/bin/bash
cat /etc/passwd | while read LINE
do
username=$(awk -v var="$LINE" -F: '{
if ($3 % 2 == 0)
print $1
}')
cp /root/nbu/file1.sh ~"$username"
done
And it does nothing. If I echo cp /root/nbu/file1.sh ~"$username"
command and execute it directly in the script, it works.
I guess the problem is that ~
gets expanded in the bash script, but can't figure out how to solve this problem.
Thank you in advance.