Exercise: Bash Features
Practice writing a command using logical operators. The solution for the given question will also be discussed.
Practice
Write the command that implements the following algorithm:
-
Copy the
/usr/share/doc/bash/README
file to the home directory. -
Archive the copied
~/README
file.
- Delete the copied
~/README
file.
Each step takes place only if the previous one succeeds. We write the result of each step to the log file result.txt
.
Solution
Let’s implement the algorithm step by step. The first action is to copy the README
file to the user’s home directory like so:
cp /usr/share/doc/bash/README ~
We use the &&
operator and the echo
command to print the ...