LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   environment variable does not exist (https://www.linuxquestions.org/questions/programming-9/environment-variable-does-not-exist-4175682520/)

doru 09-22-2020 09:49 AM

environment variable does not exist
 
Code:

$ p=password; ccrypt -eEp file.txt
ccrypt: environment variable p does not exist.
$ user@cloudm:~/tmp/test10$ export p=password; ccrypt -eEp file.txt
$ t=test; echo $t
test

ccrypt reads the password from p, but it sees it only when p is exported. Why?

doru 09-22-2020 09:54 AM

ccrypt works in some kind of subshell and it does not care to read the variable before it creates the subshell?!

rtmistler 09-22-2020 10:26 AM

Not sure, but you might have to use that "cat<<EOF" bash notation there. I'm pretty weak on that notation.

https://mytrashcode.com/cat-command-examples

pan64 09-22-2020 10:28 AM

wrong syntax:
Code:

p=password ccrypt -eEp file.txt
without ; will work, but with ; it won't.
otherwise export makes the given environment variable[s] accessible in the child processes. That is the purpose of that export.

dugan 09-22-2020 05:58 PM

Expanding on the explanation above:

Quote:

Originally Posted by doru (Post 6168551)
Code:

$ p=password; ccrypt -eEp file.txt

Well, with the semicolon, that's exactly equivalent to:

Code:

$ p=password
$ ccrypt -eEp file.txt

Do you see the problem?


All times are GMT -5. The time now is 10:38 PM.