oikool has asked for the wisdom of the Perl Monks concerning the following question:

use Time::Local my $x=localtime; print "\n","\n", $x; print "\n","\n"; system("date"); system("date -s "2 June 2010 18:00:00"");

i'm actually trying to set the date, so to print this linux command that i have mentioned in last.. how do i have to do that

Replies are listed 'Best First'.
Re: to print a system command
by robby_dobby (Hermit) on Feb 12, 2014 at 12:22 UTC
    Hello oikool,

    For now, I'm going to assume that you are an admin on your machine since executing date -s ... requires root privileges.

    As for your question, you need to properly quote your input: Use qx or other quote like operators in your system function call.

    system('date -s "2 June 2020 18:00:00"');
      Or system("date", "-s", "2 June 2010 18:00:00") which is way better since you don't need to worry about the shell that way.
Re: to print a system command
by vinoth.ree (Monsignor) on Feb 12, 2014 at 13:35 UTC
    Hi oikool

    If you need to use the double quote inside the string, you can use the backslash character.

    system("date -s \"2 June 2010 18:00:00\"");

    The single quote can be used without a backslash.


    All is well

      Better still, use a quoting construct.

      system qq{date -s "2 June 2013 18:00:00"};

      Cheers,

      JohnGG

Re: to print a system command
by Anonymous Monk on Feb 12, 2014 at 12:18 UTC