crsh

rsh is removing double quotes


rsh command is removing the double quotes in the remote shell.

For example: my command rsh 10.20.1.25 my_pgm -g "NAME1 NAME2" In remote shell my_pgm -g NAME1 NAME2

I want double quotes for -g option in remote shell too. Any idea?


Solution

  • To escape double quote inside a string use a backslash:

    rsh 10.20.1.25 my_pgm -g "\"NAME1 NAME2\""
    

    Actually, My C program is like this sprintf(cmd_string, "rsh 10.20.1.25 my_pgm -g \"NAME1 NAME2\"");

    Ok, you mean using system(), see output on echo:

    #include <stdlib.h>
    
    int main(void)
    {
        system("echo \"NAME1 NAME2\""); /* output: NAME1 NAME2 */
        system("echo '\"NAME1 NAME2\"'"); /* output: "NAME1 NAME2" */
    
        return 0;
    }
    

    Translated to yours (Note single quote and double quote around NAME1 NAME2):

    sprintf(cmd_string, "rsh 10.20.1.25 my_pgm -g '\"NAME1 NAME2\"'");

    Or as pointed out by @nos:

    sprintf(cmd_string, "rsh 10.20.1.25 my_pgm -g \\\"NAME1 NAME2\\\"");