1

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?

0

1 Answer 1

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 .