Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
422 views
in Technique[技术] by (71.8m points)

macos - Trying to go back to a "Checkpoint" in ZSH script

Ok so, I'm making a program in ZSH and I've made all the client-sided scripts that are run with commands

I'm having two problems where I need to set "Checkpoints" just like in videogame.

First Problem:

A="LUNGOTEVEREMARZIO-UMBERTO (RM-CTR54)"
B="LUNGOTEVEREMARZIO-UMBERT1 (RM-CTR55)"
vared -p 'Which device would you like to access? ' -c tmp
X=$tmp
if [[ $tmp == 'A' ]]; then
    F=${A}
elif [[ $tmp == 'B' ]]; then
  F=${B}
else
  echo 'Error, CODE176, Variable not found. Please upload logStamp.txt to Ranieri#0001 on Discord'
  log start(./logstamp.txt)
sleep 2
echo Selected Option ${tmp}: ${F}

Here, I'd like for line 13 to proceed after the variables are set, however, after the variables are set the script just stops (I understand why it does that, I just need a way to stop it. Here, is problem 2:

vared -p 'Awaiting Commands >> ' -c response
if [[ $response == 'GG stop' ]]; then
  echo '${sTT}'
  STATUS='${stopResponse}'
  
elif [ $response == 'GG start' ]]; then
echo '${srTT}'
STATUS='${startResponse}'
./TrStart.js
    
fi

Here, I'd like to go back to line 1 (vared) so that the users can input more commands. I was thinking both of the problems are similar to "Checkpoints" in VGs as i'm basically trying to go back to a selected point and be able to rerun the script from there. I thought of just repasting the entire thing in the if statementes but I know there has to be a MUCH more efficient way. Any help is much appreciated Cheers, RCdS


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You are probably looking for an infinite while loop. Here is an example based on one of your script:

#!/bin/zsh
while true; do
  vared -p 'Awaiting Commands >> ' -c response
  if [[ $response == 'GG stop' ]]; then
    echo 'Stop'
  elif [[ $response == 'GG start' ]]; then
    echo 'Start'
  fi
  response=''
done

See the Complex Commands section of the Zsh Shell Manual.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...