I fully agree with @AndreBorie, you have the shell history where the command will be logged together with the variables. e.g.
$ FOO=bar echo 3
3
$ history 2
674 FOO=bar echo 3
675 history 2
You can disable that with set +o history
for bash or the POSIX way with set -o posix; set -o nolog
(which does not work in either bash or zsh according to my tests).
On Linux you have two more files of interest: /proc/<PID>/environ
and /proc/<PID>/cmdline
. The environment file is safe from other users:
$ ls -l /proc/self/environ
-r-------- 1 grochmal users 0 Sep 28 00:51 /proc/self/environ
But the command line file, not quite:
$ ls -l /proc/self/cmdline
-r--r--r-- 1 grochmal users 0 Sep 28 00:51 /proc/self/cmdline
Fortunately the Linux folks have been there and the cmdline
file does not log the environment variables passed:
$ cat -v /proc/self/cmdline
cat^@-v^@/proc/self/cmdline^@
$ FOO=bar cat -v /proc/self/cmdline
cat^@-v^@/proc/self/cmdline^@
The important thing about /proc/<PID>/cmdline
is that it is from here that ps
takes its information about processes' command lines. Therefore these variables will not be seen in something like ps aux
or ps -afe
.