Commands Sequence
Learn how to split a long command into a series of short commands in the script.
We'll cover the following...
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
.
#!/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)
Running the bash scripts
Let’s modify ...
Access this course and 1400+ top-rated courses and projects.