How can I run a here document on just one line? I ask, because I need to issue it from C++ as a system() or similar command and for security reasons I don't want to write out a shell script file from the program and run it.
For example, how could I write:
passwd test <<EOF
n3wp3ss
n3wp3ss
EOF
as s single command? I've tried semicolons and they don't work for this.
Thanks in advance.
Brandon
will this do?
cmd=sprintf("passwd test <<EOF\nn3wp3ss\nn3wp3ss\nEOF")
system(cmd)
What security reasons are these? A plaintext password is a plaintext password no matter how you cut it. Shoving it inside a C program does not help. Just run strings on it and bam, they have your password.
You can protect it with chmod -r, of course. But that's only protection from lower users and not any protection from anyone who needs to run the program. And you could've done that for a shell script anyway.
Since you're doing it in C, you can put newlines wherever you please with \n, effectively making a multi-line string. Also note that if you put "two" "strings" in a row, they become "twostrings", so you can organize it nicely by line and still have it one giant string.
system("cat <<EOF\n"
"This is a here document\n"
"being executed in system()\n"
"EOF\n");