Having issues in shell scripting

Q.There is something wrong with the script /home/bob/update_shell.sh. Find out the issue and fix it.

This script should update the bob’s home directory and default shell if valid command-line arguments are provided but it is not working correctly.

update_shell.sh code==>

usermod -s $user_name $new_shell

unable to run the same???

1 Like

./update_shell.sh teak /bin/sh
usermod: no changes
usermod: user bob is currently used by process 203

and script looks like this
bob@caleston-lp10:~$ cat update_shell.sh
user_name="1" USER=(whoami)
echo $USER
sudo usermod -s $new_shell $USER
sudo usermod -d “/home/”$user_name $USER

Hi Navin, looks like your command syntax is wrong.
it should be usermod -s $new_shell $user_name

thank you vijin.palazhi

Hello Vijin,

I had the same issue. I had updated the order in which the new shell and user name appeared in the script as per the usermod command. It still did not work for me. I am sure I used the format
usermod -s $new_shell $user_name

I even skipped the variable name part and user the “Read Input” method but still did not work. Had to skip the last question :stuck_out_tongue:

Dear Vijan,

I am using the same command line, but it is showing an error.

#usermod -s $new_shell $user_name
usermod -s $new_shell $user_name

Please don’t forget to mention sudo before this command.
Input would be like this : bash update_shell.sh username shell
where the username will be “bob” & the shell name will be “/bin/bash”

Now in the script please make sure that you add sudo before the usermod
like this

sudo usermod -s $new_shell $user_name "

Well it worked for me! image