0

I am trying to convert a user input to datetime value but it gives invalid date error in shell script

start_time=$5' '$6
start_time=$(date --date='$start_time')

$5 the user is entering 03/12/2015 $6 the user is entering 00:10:00

david419
  • 435
  • 3
  • 8
  • 18

1 Answers1

1

Variable expansion/substitution doesn't happen with single quotes. So in :

start_time=$(date --date='$start_time')

$start_time is not substituted with its content.

However, when you use double quotes variables are first substituted before doing anything with the resultant string. So do :

start_time=$(date --date="$start_time")
sjsam
  • 21,411
  • 5
  • 55
  • 102
  • It was just an explanation to the comment by @user000001 . Good things work for you anyway. – sjsam Dec 27 '15 at 17:21