Hands-on Lab – Testing Conditions
For this step, download the tests-test.sh
script from the Github repository. (It’s a rather long script that I can’t reproduce here, due to book formatting considerations.) Open the script in your text editor, and examine how it’s constructed. The first thing you’ll see is that it’s checking for the existence of the myfile.txt
file, like this:
#!/bin/bash
[ -f myfile.txt ] && echo "This file exists." || echo "This file does not exist."
After that, you’ll see the command to create the file if it doesn’t exist, like this:
echo "We will now create myfile.txt if it does not exist, and make it with only read permissions for $USER."
[ -f myfile.txt ] || touch myfile.txt
Next, you’ll see the command to set 400
as the permissions setting, which means that the user has permission to read the file, and that nobody has permission to write to...