Commands Sequence

Learn how to split a long command into a series of short commands in the script.

The following demonstrates the script for making the photos backup:

#!/bin/bash
(tar -cjf ~/photo.tar.bz2 ~/photo &&
  echo "tar - OK" > results.txt ||
  ! echo "tar - FAILS" > results.txt) &&
(cp -f ~/photo.tar.bz2 ~/backup &&
  echo "cp - OK" >> results.txt ||
  ! echo "cp - FAILS" >> results.txt)

Click the Run button and then execute the bash script. We can observe the results by running cat results.txt.

Get hands-on with 1200+ tech skills courses.