bash - How to use functions for making decisions -
i porting 'choose own adventure' game linux. game took user input , used determine "path".
how i'd on windows:
echo turn left or right? set /p a= if %a%==left goto left if %a%==right goto right :left echo go left. echo now, continue down cave or... :right echo go right. echo now, you... ect.
how do in linux?
an 1:1 translation of code bash can written functions this
#!/bin/bash left() { echo go left. echo now, continue down cave or... } right() { echo go right. echo now, you... ect. } echo -n "do turn left or right? " read [ $a = "left" ] && left [ $a = "right" ] && right
Comments
Post a Comment