Jeffrey L. Roberts
Jeffrey L. Roberts

Reputation: 2994

bash is replacing colon with space, how do I keep the colons?

I am trying to echo a compatible MySQL datetime wit bash and it keeps replacing the colons with spaces.

Any ideas on how I can prevent them from being replaced?

Also, I have tried to replace the spaces with sed back into colons, but they still come out as spaces, what is the deal here?

#!/bin/bash
now=$(date +"%Y-%m-%d %H:%M:%S") 
EXECUTED=$(php evaluate.php $now)

Exepected Result: 2012-12-08 06:34:00

evaluate.php

var_dump($argv)

Upvotes: 1

Views: 1343

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 754730

You need double quotes around the argument to your PHP script to preserve the space in a single argument:

#!/bin/bash
now=$(date +"%Y-%m-%d %H:%M:%S") 
EXECUTED=$(php evaluate.php "$now")

Whether that's sufficient is another matter. Your PHP script seems to be missing the PHP tags.

$ php evaluate.php "$now"
array(2) {
  [0]=>
  string(12) "evaluate.php"
  [1]=>
  string(19) "2012-12-07 22:39:46"
}
$

evaluate.php

<?php
var_dump($argv)
?>

Upvotes: 1

Related Questions