problem with changing default home directory

Hi
I want to change the default home directory of a user by modifying the /etc/passwd.

I have a user named John
cat /etc/passwd | grep John

john:x:503:506::/home/john/:/bin

Here is my script:

echo "Enter username";
read username;

echo "Enter new home directory";
read new_path;

awk -v user="$username" -v path="$new_path" 'BEGIN{FS=OFS=":"}$1==user{$6=$new_path}1' /etc/passwd > /etc/passwd.new && mv /etc/passwd.new /etc/passwd;;

I enter:
john
/home/tomas

cat /etc/passwd

john:x:503:506::john:x:503:506::/home/john:/bin/bash:/bin/bash

however it should be :

john:x:503:506::/home/tomas/:/bin

How can I correct it?

Logic, let's paint the problem:

username=john
new_path=/home/tomas
awk -v user="$username" -v path="$new_path" 'BEGIN{FS=OFS=":"}$1==user{$6=path}1' /etc/passwd > /etc/passwd.new && mv /etc/passwd.new /etc/passwd;;

On modern Solaris (10) and many linuces you can use the command usermod, quite useful.

usermod -d /path/to/new/home target_username

/fimblo

That worked, thanks a lot