Reputation: 298
Hi I get the below error when I try to execute the below code:
date_input= '2015-01-25'
date_parameter=$(date -d `echo $date_input` +%s)
min_date=$(date -d 2015-11-01 +%s)
max_date=$(date -d $(date +"%Y-%m-%d") +%s)
if [ "$date_parameter" -gt "$max_date" ] || [ "$date_parameter" -lt "$min_date" ]; then
Error -> [: : integer expression expected
Upvotes: 0
Views: 54
Reputation: 785146
You can fix your script by using:
date_input='2015-01-25'
date_parameter=$(date -d "$date_input" '+%s')
min_date=$(date -d 2015-11-01 '+%s')
max_date=$(date '+%s')
[[ $date_parameter -gt $max_date || $date_parameter -lt $min_date ]] &&
echo "ok" || echo "nope"
Upvotes: 3