This site is for tech Q&A. Please keep your posts focused on the subject at hand.

Ask one question at a time. Don't conflate multiple problems into a single question.

Make sure to include all relevant information in your posts. Try to avoid linking to external sites.

Links to documentation are fine, but in addition you should also quote the relevant parts in your posts.

0 votes

I need to extract information from a process environment (/proc/<PID>/environ). The content of those files is separated by null bytes, so I thought I'd use xargs to output the values line by line:

xargs -0 echo < /proc/2342/environ

However, this seems to output everything in one line, just separated by spaces instead of null characters.

in Scripting
retagged by
by (100)
3 9
edit history

Your answer


Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
By submitting this post you agree to our Terms & Conditions.
To avoid this verification in future, please log in or register.

1 Answer

0 votes

If you want to use xargs you need to tell it to process the input one line at a time (-L1), otherwise echo will output the entire input at once (thus mangling all input lines into a space-separated string).

xargs -0 -L1 echo < /proc/2342/environ

You don't need the redirection, though, since xargs can read the input file directly (parameter -a), and echo is the default command, so you can omit that too:

xargs -0 -L1 -a /proc/2342/environ

Alternatively, you could achieve the same result by using tr to replace null characters with newlines:

tr '\0' '\n' < /proc/2342/environ
by (100)
3 9
edit history