0

This question already has an answer here:

Given a parameter $1, I want to subtract 5 minutes from that time, and echo it (later reuse the variable).

echo $1
time5=date -d "$1 5 minutes ago" +'%H:%M'
echo ${time5}

Call with: ./script.sh 16:55

Result:

prints 16:50

./script.sh: line 2: -d: command not found

Why can't I assign the date to the variable time5?

marked as duplicate by Yaron, muru bash Sep 13 '17 at 8:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

6

You can use the $() operator for this:

echo "$1"
time5=$(date -d "$1 5 minutes ago" +'%H:%M')
echo "$time5"

Not the answer you're looking for? Browse other questions tagged or ask your own question.