How to read content from environment file?
Hi, guys.
I plan to read some words from environment files, such as $(HOME)/.bash How can I open such files and fetch lines? Thanks a lot! |
In what programming language?
|
And what shell?
|
o, is it related to language and shell?
It's C language on linux shell. And the complete path is $(HOME)/.adcl/config.adcl Thanks! |
How long have you been doing GNU/Linux & how long have you been doing C?
I don't mean that to sound rude, but ... There is no "linux shell" per se, only a default linux shell, which is bash. Is this the shell you are referring to? Also, opening files & reading them is almost the next lesson after "Hello World" in learning a programming language; if you need to do this in C, I suggest a text book. (And, unfortunately, I don't do C, so I can't make any recommendations.) Finally, are you sure "$(HOME)" is correct syntax? In bash that would be "${HOME}", or "$HOME", or just "~". |
archtoad6:
Thanks for reply. I wrote shell scripts before, seldom people call that bash scripts. So when you ask what shell, I also doubt us there any else shell?:) Sure, I know how to open/read/write user-defined files in C. However, I don't know how to access environment variables such as $HOME and .adcl in c programming. That's why I post my questin here. More specified, my question is how to open $HOME/.adcl/config.adcl in C? |
Quote:
Quote:
Code:
/* example.c - How to use an environment variable in C */ Code:
gcc -Wall -o example example.c |
Ah, a C person answered while I was composing this. I think you need to use Google to learn about the variety shells available in GNU/Linux.
You also should have used it to get the answer to your underlying question before posting here. Remember, I already said I don't write C, but I still found your basic answer w/ 1 search Google Linux: C "access envirronment variables" |
Thank you HKO very much.
I don't expect to have the complete or exactly answer here, but you know, any suggestion or advice is a good advice to go ahead in a correct direction. And we can also learn more from others' posts. I thinks that's the reason why many people post questions here. |
All times are GMT -5. The time now is 02:54 AM. |