Script Parameters

Learn how to change the Bash script's behavior using parameters.

Parametrizing the photo directory

Let’s suppose we moved our photos from the ∼/photo directory to ∼/Documents/Photo. If we want to support the new path in the backup script, we should change its code. The following shows how the new script looks:

#!/bin/bash

tar -cjf ~/photo.tar.bz2 ~/Documents/Photo &&
  echo "tar - OK" > results.txt ||
  { echo "tar - FAILS" > results.txt ; exit 1 ; }

cp -f ~/photo.tar.bz2 ~/backup &&
  echo "cp - OK" >> results.txt ||
  ! echo "cp - FAILS" >> results.txt

Every time we move the photos from ...

Access this course and 1400+ top-rated courses and projects.