简体   繁体   中英

port bash script to anything that can be run on windows

I'm having great difficulty porting a very basic application that I created using mostly bash, which runs on OS X Terminal.

I need to run a similar version of this program on a Windows laptop, so feel that I need to basically rewrite the code. I've tried Linux emulators, and the new Windows 10 bash integration, though features I've used are buggy or do not work.

examples of the simple things I need it to do:

export lev=/home/user/dir  
export shu=/home/user/dir 
export laptime=/home/user/dir 
export currLaptime=/home/user/dir 
export currLaptime=/home/user/dir 
export infant=/home/user/dir 

lev=1;
shu=0;
increments=0.5;
cpuDelay=0.35;


declare -a laptime=('1' '1' '1' '1' '1' '1' '1' '1' '1' '1' '1' '1' '1');
say "Distance?";
read distance infant;
if [[ $infant == "i" ]]; then speed=5.5; else speed=6.5; fi
echo $speed "kph";

n=0;
speedCalc=$speed;
for i in `seq 1 21`;
do  laptime[n]=$(awk "BEGIN {print ${distance}/($speedCalc/3.6); exit}");
    laps[n]=$(awk "BEGIN {print 60/${laptime[n]}; exit}");
    laps[n]=$(printf '%.0f' "${laps[n]}");
    let n+=1;
    speedCalc=$(awk "BEGIN {print ${speedCalc} + 0.5; exit}");
done;

turningRoundTime=$(awk "BEGIN {print ( ( ${distance} * 0.02 - 0.29 ) * -5 ); exit}");
laptimeAdjustment=$(awk "BEGIN {print ${turningRoundTime}-$cpuDelay; exit}");


n=0;
for i in `seq 1 21`;
do  laptime[n]=$(awk "BEGIN {print ${laptime[n]}+$laptimeAdjustment; exit}");
    let n+=1;
done;

echo "cpu delay: $cpuDelay";
echo "Turning round time: $turningRoundTime";
echo "laptime adjustment: $laptimeAdjustment";

for i in `seq 1 21`;
do
currLaptime=${laptime[lev-1]};
    for i in `seq 1 ${laps[lev-1]}`;
    do
            parallel sh ::: announceLevel.sh sleep.sh; shu=$((shu+1)); 
    done
lev=$((lev+1)); shu=0;

Feel like I'm ready to go back to scratch and create this in another language, one that could be made into an application that might run on Windows, or perhaps Android in future. It works beautifully on the environment that I have set up on OS X, but I just need an indication of which direction to go if I'm to have this run on any other environment.

Many thanks!

Nick

Have you tried Cygwin under Windows? (GPL/LGPL/etc/Open Source.) The default mintty cygwin terminal emulator works pretty well. You can get BASH and whatever else you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM