User input not reading correctly in bash -
i have data that's held in 1 of 3 directories , wanted create loop allow user access data.
i'm trying make loop work if enters 1-3 reads number , changes variable timeperiod either "daily", "bars10s", or "bars100ms". when echo timecheck , timeperiod variables when running code see if they're ok, timecheck comes right, timeperiod reads "daily" no matter timecheck variable reads as. i'm pretty new bash, appreciated.
#!/bin/bash echo timeperiod="" timecheck=0 read -p "time period fac run(press 1 daily, 2 10 sec intervals, 3 100ms intervals): " -e -i "$timecheck" timecheck if [ $timecheck==1 ] ; timeperiod="daily" elif [ $timecheck==2 ] ; timeperiod="bars10s" elif [ $timecheck==3 ] ; timeperiod="bars100ms" else echo "not valid time period. please re-try." fi echo $timecheck echo $timeperiod
you can use select - menus this.
ps3="select want>" select answer in "daily period" "10 sec period" "100 ms" "exit program" case "$reply" in 1) timeperiod="daily" ; break;; 2) timeperiod="10s" ; break;; 3) timeperiod="100ms" ; break;; 4) exit ;; esac done echo "$timeperiod"
Comments
Post a Comment