Quoting a system call - double vs single

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DannyMc
    New Member
    • Aug 2007
    • 20

    Quoting a system call - double vs single

    Hi, i faced a problem while executing code in double quote "" and single quote ''

    let say example, we type in manually:

    >ls abc | grep "\.\/"

    it works.

    and when i implement this into my script.

    $cmd1 = "ls abc | grep '\.\/'" #------> not working
    $cmd2 = "ls abc | grep \"\.\/\" # same like previous.

    Is my syntax correct ? Please advice. Thank you.
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Not exactly. When you run a system level command in Perl, you either use the system function, or you have to put the system level command in back tics. They essentially do the same thing. Here is how your command should look:

    [code=perl]
    my $cmd1 = 'ls abc | grep "./"';
    [/code]

    I don't have my linux box up at the moment to test if you need the leading"\" characters, but you can play with it and see what works for you to get the results you want.

    Regards,

    Jeff

    Comment

    • DannyMc
      New Member
      • Aug 2007
      • 20

      #3
      Thanks Jeff, you reminded me to put the 'single quote' first before the "double" quote!! I have solved my minor problem now.

      Actually i have created a function to search for files for me inside a system. i will named it "getme" in this case.

      >getme name.cpp

      my function will print the result like this

      File(s) Found:

      ./abc
      ./123
      ./321

      So i just want to grep the result which is ./abc instead of the whole printed message.

      "\" forward slash is important in the grep. Without \ , it result still print complete message. You can have a try with webbased ubuntu. :)

      Thank you once again , i appreciate it !

      Comment

      Working...