5 Modern Bash Scripting Techniques That Only a Few Programmers Know
From Create Loading Animations
Go to text →
#!/bin/bash
while true;
do
# Frame #1
printf "\r< Loading..."
sleep 0.5
# Frame #2
printf "\r> Loading..."
sleep 0.5
done
or
#!/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"
From Displaying Native Gui Notifications from Bash
Go to text →
Linux
#!/bin/bash
sleep 10
notify-send "notify.sh" "Task #1 was completed successfully"
OSX
#!/bin/bash
sleep 10
osascript -e "display notification \"Task #1 was completed successfully\" with title \"notify.sh\""
From Multiprocessing in Bash Scripts
Go to text →
#!/bin/bash
function task1() {
echo "Running task1..."
sleep 5
}
function task2() {
echo "Running task2..."
sleep 5
}
task1 &
task2 &
wait
echo "All done!"
the wait
builtin makes sure that all background processes have completed before carrying on