Have some bash test code that have a spinner. Code seems like this
#!/bin/bash
sleep 5 &
pid=$!
frames="/ | \\ -"
while kill -0 $pid 2&>1 > /dev/null;
do
for frame in $frames;
do
printf "\r$frame Loading..."
sleep 0.5
done
done
printf "\n"
This code is write on a inline step.
The problem is, in output screen, spinner shows like this
/ Loading...| Loading...\ Loading...- Loading.../ Loading...| Loading...\ Loading...- Loading.../ Loading...| Loading...\ Loading...- Loading...
Anybody knows how to handle this situation in rundeck?
CodePudding user response:
Use echo
instead of printf
(take a look), but even using echo
Rundeck output doesn't work as an interactive terminal, which means that you can't see the bar spinning.
Each update is printed as a new line/string. The best way is to see a "loading" effect is using an "update line", e.g:
x=1
echo "starting..."
while [ $x -le 5 ]
do
sleep 2
echo "***"
x=$(( $x 1 ))
done
echo "done!"
CodePudding user response:
I don't know what "Rundeck" is or what your kill line is trying to do but in terms of implementing a spinner in bash, this works perfectly for me:
$ cat tst.sh
#!/usr/bin/env bash
frames=( '\\' '|' '/' '-' )
cnt=0
while (( cnt < 10 ))
do
for frame in "${frames[@]}"
do
printf "\r$frame Loading..."
sleep 0.5
done
done
printf "\n"
There's no way to see it spinning here of course but FWIW:
$ ./tst.sh
/ Loading...