bash - Scrolling through array positively and negatively -
i'm creating script the user presented 10 files , give user option scroll next page using 1 , 2 on keyboard input. have written following script can't achieve seem happen. in regards appreciated!
example:
1) previous page 2) next page 3) contact details 4) main menu
those options user use or enter when prompted. have written sample script doesn't give me result because of logical error , index counter go negative (i'm assuming passes through first if
)
declare -a manual=("$pg1" "$pg2" "$pg3" "$pg4" "$pg5" "$pg6" "$pg7" "$pg8" "$pg9" "$pg10") x=0 while [ $x -lt "10" ] read if [ -eq 1 ]; echo ${manual[$x-1]} x=$(($x-1)) elif [ -eq 2 ]; echo ${manual[$x+1]} x=$(($x+1)) elif [ -eq 3 ]; echo ${manual[10]} else [ -eq 4 ]; bash mainmenu.sh fi done
i'm new scripting , answers helpful!
you need replace a
$a
in if statements of script:
e.g. :
if [ $a -eq 1 ];
you may change test @ beginning of loop check value of x positive or null, x
doesn't go out of range:
if [ $a -eq 1 -a $x -gt 0 ];
Comments
Post a Comment