shell

All things command-line wizardry.

One-line if, for, etc.

# one-line if statements
if true; then echo "Do something"; fi
# => Do something

if false; then echo "Do something"; fi
# =>
# one-line for statements

for i in hello there; do echo $i; done
# => hello
# => there

for i in $(seq 1 3); do echo $i; done
# => 1
# => 2
# => 3

Infinite loop

You'll often need to run a command over and over again for some reason (mine right now is: I have to check if a file exists). There are obviously better options - but doing things through command-line ninjutsu is always funnier. So, one-line infinite loops in Shell (both sh and Bash):

while true; do echo "Doing some work" && sleep 1; done
# => Doing some work
# => Doing some work
# => Doing some work
# => ...

This will run echo "Hello!" forever, "sleeping" for one second between each execution.