I'm very new to the world of bash scripts and require some assistance. I want to increment a variable by 1 when I provide the script with a certain command line input and decrement it by 1 when providing a different command line input but I don't want to be able to decrement lower than zero. How can I go about this?
My thought process is somewhat like this. I need a counter that starts at zero and some way to read the command line input. Then two if statements that check the input and the count and if both are valid then either do the increment or decrement.
count=0 read input if(input == "in" && count >= 0) let "count++" if(input == "out" && count > 0) let "count--" echo $count
but I'm not sure about the syntax since I'm very new to bash. Am I on the right track at all? Any help would be appreciated.