shell doubt

General support questions
Post Reply
knzzz
Posts: 157
Joined: 2017/02/25 12:41:42

shell doubt

Post by knzzz » 2018/02/20 09:39:26

Hi Team,

can some one please clarify my doubt , in case if i want to back to 10 steps in the shell script follow how can i going in shell scripting.

For eg

In case if i get a set of inputs , before processing the input data i got some wrong information from the inputs which i got , without exiting the shell scirpt follow how can i get the inputs from step 1.


Regards
Kanna

MartinR
Posts: 714
Joined: 2015/05/11 07:53:27
Location: UK

Re: shell doubt

Post by MartinR » 2018/02/20 11:52:36

Something like this?

Code: Select all

#!/bin/sh
bad=true						# Ensure "bad" is set.
while $bad						# Whilst the input is bad ...
do
    read -p "Enter letter: " buffer		# ... get new input.
    [[ $buffer == "Y" ]] && bad=false	# If the input is ok then it isnt bad
done

MartinR
Posts: 714
Joined: 2015/05/11 07:53:27
Location: UK

Re: shell doubt

Post by MartinR » 2018/02/21 13:38:58

Your PM ask for more help, I'm posting it here to ensure it is visible to all.
In case if i get a set of inputs , before processing the input data i got some wrong information from the inputs which i got , without exiting the shell scirpt follow how can i get the inputs from step 1
If I understand you correctly, you want to get some inputs, check that they are valid and if you have "some wrong information from the inputs" then you want to go back to get more information. If the input is valid you want to continue to process the input data.

The example I gave shows this in outline:

I used the read statement to simulate your "get some inputs". You'll need to substitute your own code here. Next I checked to see if the input was valid; "Y" is valid, anything else is "wrong information". Again, you need to substitute your own tests for validity here. If the test is valid, then I set the variable "bad" to false - ie it is "NOT bad". Now it is a simple thing to jacket the input-test pair in a do loop which will continue whilst there is bad input and exit when there is good. You can then add your processing steps after the done statement.

Of course, if I've misunderstood what you were trying to do, then this is probably not very helpful! ;)

Post Reply