Behavior of environment variables


I am a Linux beginner before anything.

I have been trying to add an environment variable into /etc/environment as NULL=“2>/dev/null”

I’ve tried this without quotes, with spaces and such to no avail. What could fix the above variable declaration?

That looks fine to me. Perhaps the problem is how you’re trying to use that variable? You’ll have to explain that a bit more.

If you’re trying to figure out what’s wrong with the shell command or script you are trying to run, you can use the ShellCheck website to debug:

Hello, and thanks! I forgot I’d posted this for a bit, I’m afraid.

It appears I need to do NULL=2> /dev/null
or NULL=“2>\ /dev/null”,
for that shell checker to get satisfied.

Escaping spaces has fixed other variables for me, so I probably figured the matter out before I got back to this post, though I have yet to try it properly with this NULL variable. Little later.

I realize I did not provide very complete info earlier, so what I’ve been trying to do is to become able to type,
find / -name XXX $NULL
instead of,
find / -name XXX 2>/dev/null
, as I did quickly notice my wanting to redirect away all errors for virtually every search I did. However, by including the redirection as part of the variable $NULL, I receive the following error:
find: paths must precede expression: ‘2>/dev/null’

I’d assume there’s some basic error I am making here, involving how the ‘2’ and ‘>’ are being interpreted when they’re part of the variable as opposed to being explicitly stated, so for the moment I’m simply continuing to learn more about the fundamentals until the matter becomes clear.

I did try escaping this and that, adding a space after ‘>’, adding the variable to /etc/environment and as temporary declarations, dividing up the declaration into two “” parts, but clearly it all got too messy as I’m clearly guessing about too many things.