Thank you Nikilesh. I'll try taking away the exit commands and try again. Ill let you know how it goes. Thank you.
On Sun, 3 May, 2020, 12:13 AM Nikhilesh Susarla, <[email protected]> wrote: > On Sat, May 2, 2020, 21:15 Muhammed Suhail <[email protected]> > wrote: > >> Hey I'm trying to run the following script. But the program is not >> running after the initial input stage: >> >> #!/bin/bash >> >> if [[ $UID != 0 ]] >> then >> exit 1 >> fi >> >> if [[ $?=0 ]] >> > > Assuming you checking for equality rather than assignment. > > then >> read -p 'Enter the new username' $user_name >> read -p 'Enter Real name' $comment >> read -p 'Enter password' $password >> exit 0 >> else >> exit 1 >> fi >> > > I didn't run this code. But according to my assumptions, exit 0 or exit 1, > will exit your bash script and anything further won't execute. > > I'm unsure why you placed exit in both the if else and have code beneath. > > If your previous command has failed, which won't return you an exit status > ($?) Zero. Then you can exit. As you wrote in the else exit 1. > But I don't think exit 0 is really required. > > >> #create account - The code is not running from here >> if [[ "$?" -eq 0 ]] >> then >> useradd -c $comment -m $user_name >> echo $password | pwrd --stdin ${user_name} >> echo Working... >> exit 0 >> fi >> >> if [[ $? == 0 ]] >> then >> echo "Account Created" "Username: ${user_name}, Host: ${HOSTNAME}" >> > > Might be if you want your code to working as you wanted. You can separate > them into two scipts and have a main script which calls the script 1 and > script2. > > Thank you. > Susarla Nikhilesh >

