change-time: Test date exit status directly

There's no need to try to parse stdout/stderr to figure out if date
succeeded, just check if it was successful directly.

Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
This commit is contained in:
Jonathon Hall 2024-08-06 09:22:59 -04:00
parent 770815cba8
commit a1343666d5
No known key found for this signature in database
GPG Key ID: 1E9C3CA91AE25114

View File

@ -49,11 +49,7 @@ min=$value
get_date "second" "00" "59" "2"
sec=$value
##getting the output of date -s
OUTPUT=$(date -s "$year-$month-$day $hour:$min:$sec" 2>&1)
##if output is starting with the letter d which is the beginning of the error message then we do the script again
if [[ ${OUTPUT} == d* ]]; then
if ! date -s "$year-$month-$day $hour:$min:$sec" &>/dev/null; then
echo "The date is not correct, press any key to try again"
echo -e "\n"
read -n 1 nothing