Skip to content

Instantly share code, notes, and snippets.

@alex0112
Created October 22, 2022 05:17
Show Gist options
  • Save alex0112/9ea59c81f4a8013d6a1d98b9d6d33f48 to your computer and use it in GitHub Desktop.
Save alex0112/9ea59c81f4a8013d6a1d98b9d6d33f48 to your computer and use it in GitHub Desktop.
#!/bin/bash
## This abomination of a shell script was created by kingsfoil in Oct 2022
## in order to answer this SE question: https://unix.stackexchange.com/a/722000/40507
function slice_loop () { ## grab a slice of a string, and if you go past the end loop back around
local str="$1"
local start=$2
local how_many=$3
local len=${#str};
local result="";
for ((i=0; i < how_many; i++))
do
local index=$(((start+i) % len)) ## Grab the index of the needed char (wrapping around if need be)
local char="${str:index:1}" ## Select the character at that index
local result="$result$char" ## Append to result
done
echo -n $result
}
msg="Hello There! ";
begin=0
while :
do
slice=$(slice_loop "$msg" $begin 14);
echo -ne "\r";
echo -n $slice;
echo -ne " \r";
sleep 0.08;
((begin=begin+1));
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment