Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 1
    Note that /proc/7610/cmdline contains NULs, which aren't visible in the terminal but very much exist Commented Jan 19, 2021 at 22:17
  • ...consider cmdline=( ); while IFS= read -r -d '' piece; do cmdline+=( "$piece" ); done </proc/7610/cmdline; printf '%q ' "${cmdline[@]}"; printf '\n' if you want to write a command-line list out to the terminal for human consumption (or written elsewhere for a shell-compatible parser to read) unambiguously. Commented Jan 19, 2021 at 22:17
  • Yes, I have mentioned \u0000, which is \x00 or NUL in other words. Commented Jan 20, 2021 at 5:21
  • @CharlesDuffy, an easier way to print the cmdline would be xargs -0 echo < /proc/pid/cmdline. Commented Feb 23, 2024 at 22:18
  • @Juergen, that's deeply buggy. Using that practice you can't tell the difference between ./program "one argument" and ./program "one" "argument"; the point of printf %q is that it escapes strings with nonprintable characters unambiguously, so you can tell the difference (f/e) between spaces and tabs, or get output that tells you how to escape a non-breaking space in such a way as to reproduce the command line that was run. Commented Feb 24, 2024 at 14:54