May 2013
Beginner to intermediate
384 pages
7h 40m
English
When using your shell for everyday tasks, there will be cases where a command might succeed only after some conditions are met, or the operation depends on an external event (such as a file being available to download). In such cases, one might want to run a command repeatedly until it succeeds.
Define a function in the following way:
repeat()
{
while true
do
$@ && return
done
}Or, add this to your shell's rc file for ease of use:
repeat() { while true; do $@ && return; done }We create a function called repeat that has an infinite while loop, which attempts to run the command passed as a parameter (accessed by $@) to the function. It then returns if the command was successful, thereby ...
Read now
Unlock full access