I have a basic question but not able to figure it out how to do this.
I need to frame a command string with a password from a C file and need to execute that command.I am using Linux.
what I am doing is
sprintf(command, "mycommand with password=$passw'ord");
system(command);
The issue what I am facing is when I am using '
during the command execution as follow '$passw\\'ord'
,it is not working.
when tried as follow
sprintf(command, "mycommand with password='$passw\\'ord'");
//not working it showing >
in the terminal and showing error as unterminated '
but when passing only '$password'
is working ,but I need to pass the '
character also.
To try we can use
echo '$password' //working
echo '$passw\\'ord' //Not working
Is there any thing for this.
Except the single-quote ( '
) character, everything else can be included inside a single-quoted string and with no escapes. Bash makes no special interpretation of single-quoted strings and and just passes through the literal characters.
Remember that mixing single and double-quoted strings freely is supported. Thus
$ echo 'my command with password=$passw'"'"'ord'
my command with password=$passw'ord
works. In C this would translate into
char const *cmd = "'my command with password=$passw'\"'\"'ord'";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.