Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a Bash Guide for Beginners (sec. Local variables) there is an example command which is supposed to list all of the local variables, that are not in enviromental variables, or so I think:

diff set.sorted printenv.sorted | grep "<" | awk '{ print $2 }'

Now I believe I understand everything about this command except the *.sorted part. Furthermore this command doesn't work on my Bash specifically because of the above elements. Here is the response (it's the polish No such file or directory):

diff: set.sorted: Nie ma takiego pliku ani katalogu
diff: printenv.sorted: Nie ma takiego pliku ani katalogu

Worth noting is that I use Ubuntu 14.04 with close to no changes to its default installation.

Anyway because of this I am unable to analyze this command in my Bash, nor was I able to find anything about this on Google except the very tutorial I took this command from.

I will be grateful for a comprehensive explanation since I never encountered such a expression before.

share|improve this question
For future reference, you can run a command with LANG=C command to get output in English for posting on sites like this one. For example: LANG=C diff set.sorted printenv.sorted . – terdon Jan 13 at 14:40
up vote 18 down vote accepted

They're not expressions, they're filenames for files produced as follows:

 printenv | sort > printenv.sorted
 set | sort > set.sorted

That's not clear from the documentation so your confusion is understandable!

Note that you may need to help diff and grep by forcing them to treat their inputs as text (with -a); environment variables can contain values which will cause them to treat their input as binary, which won't produce anything useful:

diff -a set.sorted printenv.sorted | grep -a "<" | awk '{ print $2 }'

Better still, use comm to compare the two files:

comm -23 set.sorted printenv.sorted

You can replace the files with process substitutions:

comm -23 <(set|sort) <(printenv|sort)

to avoid creating files.

share|improve this answer
How did you get this? I don't see those commands in the guide at all! – Dmitry Grigoryev Jan 13 at 14:47
By interpreting the introductory sentence, "Below is a diff file made by comparing printenv and set output"; since the command doesn't run printenv or set, I guessed the files given to diff were the output, which has to be sorted for the comparison to be meaningful. – Stephen Kitt Jan 13 at 14:55
To an experienced *nix user, what @StephenKitt inferred is blatantly obvious. To the stated audience of a "for Beginners" guide, he might as well be a psychic peering into a crystal ball. The author of the guide should explicitly spell out the two commands as Stephen has done here so that the beginners will be able to connect the dots. – Monty Harder Jan 13 at 22:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.