Reputation: 149
I'm creating a script where the the user would be presented 10 files and I would like to give the user the option to scroll to the next page using 1 and 2 on the keyboard as their input. I have written the following script however I can't achieve what I seem to happen. Any help in regards to this would be greatly appreciated!
Example:
1) Previous page
2) Next page
3) Contact Details
4) Main menu
Those would be the options that a user could use or enter when prompted. I have written a sample script however it doesn't give me the result that I would like probably because of a logical error and the index counter always go negative (I'm assuming it only passes through the first if
)
declare -a manual=("$pg1" "$pg2" "$pg3" "$pg4" "$pg5" "$pg6" "$pg7" "$pg8" "$pg9" "$pg10")
x=0
while [ $x -lt "10" ]
do
read a
if [ a -eq 1 ];
then echo ${manual[$x-1]}
x=$(($x-1))
elif [ a -eq 2 ];
then echo ${manual[$x+1]}
x=$(($x+1))
elif [ a -eq 3 ];
then echo ${manual[10]}
else [ a -eq 4 ];
bash mainmenu.sh
fi
done
I'm fairly new to scripting to help and answers would be very helpful!
Upvotes: 1
Views: 63
Reputation: 81
you need to replace a
with $a
in the if statements of your script:
e.g. :
if [ $a -eq 1 ];
you may also change the test at the beginning of the loop to check that the value of x is positive or null, so that x
doesn't go out of range:
if [ $a -eq 1 -a $x -gt 0 ];
Upvotes: 2