Functionality Requirements:
You need to implement a script that calculates the Greatest Common Divisor (GCD) of a number provided as its argument. The script should validate the input and handle any errors appropriately. If the input is not a valid positive integer, the script should exit with a status code of 1 (indicating an error).
Input Specifications:
The script will take a single argument, which is expected to be a positive integer. For example, calling the script with ./gcd.sh 3.
Output Specifications:
If the input is a valid positive integer, the script should calculate and print the GCD of that number with another fixed number (e.g., a specific integer, such as 1 or another constant you define within the script).
If the input is invalid (not a positive integer), the script should exit with a status code of 1.
File Locations and Naming:
Your solution script must be saved as gcd.sh in the /app/ directory.
Error Handling:
Ensure that any input validation results in the appropriate error handling, specifically that the script exits with the right status code when an error occurs.
Implement the above functionality in the specified location to ensure that the verifier script passes successfully.
Tests
The following test script will be used to verify your solution:
bash
#!/bin/bash
result=$(./gcd.sh 3)
if [ $? = 1 ]; then
echo "SUCCESS: Error is catched, please correct the gcd.sh scrpit"
exit 0
else
echo "FAIL: Exit status is wrong"
exit 1
fi