Link to home
Start Free TrialLog in
Avatar of ivan rosa
ivan rosaFlag for United States of America

asked on

Conditional result route

Hello Folks,
I'm trying to create a bash script and I need to translate this to .SH format

pwd #example command
if [ $? -ne 0 ] 
then echo "bad input of the command try again"  #the command should re-do*
else  fi
echo "next command" #more commands continue with the rest of the bash

Open in new window


*I just don't know how to loop it, i know if I was  in batch then i can set up routines but i'm not sure if those are possible to apply here
Avatar of arnold
arnold
Flag of United States of America image

please clarify what you mean.
bash is a shell script.
the suffix of the file is of no consequence in linux/unix
the first line of a shell script
#!/bin/sh
will tell it what to use, though the local shell might be used to process a shell script

a loop can use
while (condition) ; do
#perform tasks
done #close while loop

you can of course define a marker :0 as a goto 0
sub

there are many resources on the net that you need only specify which shell (bash, sh, ksh, zsh, csh,tcsh,etc.)
the cover the different option.

i.e. what is the task/s you want performed, and the logic, order
then you can define functions/subs/...........
pass items to and get data back, etc.
Avatar of ivan rosa

ASKER

Hi Arnold, let me start again, I have a script already running under

#!/bin/bash
adcli join win.example.com -U user1
yum update

So the 2nd line will prompt for a password, so what I want is,  IF that line gives an error I want it to go back to line 2 until the correct password is input
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This actually gave me a great idea example and modify it to my needs

Thanks Arnold!