Exercise: If Statement

Put to practice what you have learned about if statements.

We'll cover the following

Exercise

Below is a Bash command:

( grep -RlZ "bash" target | xargs -0 cp -t . && echo "cp - OK" || ! echo "cp - FAILS" ) && ( grep -RLZ "bash" target | xargs -0 rm && echo "rm - OK" || echo "rm - FAILS" )

It looks for the string “bash” in the files of the directory named target. If the file contains the string, it’s copied to the current directory. If there is no string in the file, it’s removed from the target directory.

Make the script from this command. Replace the && and || operators with the if statements.

Get hands-on with 1200+ tech skills courses.