3 ms·
Without using printenv or grep -F (in shell script /bin/fgrep) $ export FRED=value $ set|grep FRED FRED='value' $ FRED= $ set|grep FRED FRED=
by 1vuio0pswjnm7 3y ago
Without using printenv or grep -F (in shell script /bin/fgrep)
$ export FRED=value
$ set|grep FRED
FRED='value'
$ FRED=
$ set|grep FRED
FRED=''
$ unset FRED
$ set|grep FRED
$ # ie, no output from set
(Missed a dollar sign.)
Another thing is that printenv does not make it easy to see spaces or other nonprinting characters in the values of environmental variables. For example PS="# " displays as PS=#. TAB=$(printf '\11') displays as TAB=. For me, that's not really helpful. Whereas the builtin set command displays the values in single quotes so one can easily the presence of spaces and other non-printing characters.
A workaround is to use printenv with sed, something like
printenv|sed -n l
If I was going to investigate "single command environmental variables" I might just use getenv and printf. That way I can see the non-printable characters. But not being an IT person or a programmer, maybe I am missing the reason why printenv, written in 1979, would be preferable to getenv. (That, IMO, would be an interesting blog post.) For example,
int printf(const char *__restrict, ...);
char *getenv(const char *);
int main()
{
if(getenv("FRED"))
printf("%s=%s\n","FRED",getenv("FRED"));
return 0;
}
usage: FRED= a.out