LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   eval $PATH produces a path list followed by No such file or directory warning (http://www.linuxquestions.org/questions/linux-newbie-8/eval-%24path-produces-a-path-list-followed-by-no-such-file-or-directory-warning-4175435213/)

Alpha90 11-02-2012 03:00 AM

eval $PATH produces a path list followed by No such file or directory warning
 
I have been teaching myself bash scripting and I wanted to add a bin subdirectory in my home directory so i backed up my .bash_profile and modified the path and when i used eval it gave my path list including my new directory and spit out the no such file or directory warning so i restored my copy and same deal. Is this some sort of bug or a problem on my part.

catkin 11-02-2012 03:51 AM

How why are you using eval in conjunction with the changed .bash_profile? The source command is more appropriate for testing.

millgates 11-02-2012 03:52 AM

May I ask how and why you used eval? How did you modify the PATH? In the terminal or in .bash_profile or .bashrc? What file/directory does it complain about?

Alpha90 11-02-2012 04:46 PM

Oh I am sorry I was not clear I used eval at the cli not in the bash_profile and I don't know which directory it says it after the list prints

TobiSGD 11-02-2012 05:31 PM

Please post the exact command you typed in, the exact error message you got and the changes you made to your Bash configuration.

shivaa 11-02-2012 08:50 PM

If you want to add any dir. to your PATH variable, then add following lines at the end of ~/.bash_profile or ~/.bashrc file:
Quote:

PATH=$PATH:/path/to/dir
export PATH
For example:
PATH=$PATH:/opt/bin/
export PATH
Simply append these two lines at the end of your .bash_profile or .bashrc file. Fyi, these files get sourced automatically when you login. So either exit from session to take new path into effect or do as "source ~/.bash_profile" or "source ~/.bashrc"

David the H. 11-03-2012 01:53 PM

Incidentally, you should also not be playing around with eval unless you know exactly what you're doing.

Eval command and security issues
http://mywiki.wooledge.org/BashFAQ/048


99% of the time eval is not only completely unnecessary, it is the wrong choice. Most often we see it used to do things like creating dynamic variable names, when modern shells have other, safer options such as arrays available.

As the saying goes, if eval is the answer, then you're asking the wrong question.

Alpha90 11-03-2012 08:06 PM

Y
 
Thank you shivaa I will modify my profile that way.

To David the H. How can I find the value of an environmental variable from command line ?

suicidaleggroll 11-03-2012 08:16 PM

Quote:

Originally Posted by Alpha90 (Post 4821682)
How can I find the value of an environmental variable from command line ?

Code:

echo $PATH
Replacing PATH with whatever env variable you want to check. If you want to see all env variables, run "printenv"

shivaa 11-03-2012 09:54 PM

Quote:

To David the H. How can I find the value of an environmental variable from command line ?
The cmd "printenv" will work in c shell, but instead of this, just use "env" cmd. It will work with bash shell or even with all available shells.
To check value of any env. variable, invoke:-
Quote:

% env | grep "<variable_name>"
E.g. % env | grep HOME
HOME=/home/jack

David the H. 11-04-2012 10:16 AM

As mentioned, to see the current value of any parameter, just echo it. Be sure to add double quotes around them to protect the contents from being further evaluated by the shell.

To list all existing parameters, or a specific set, in bash I usually just use the declare built-in, rather than the external env or printenv. It can display existing values as well as set them. Run help declare for a synopsis of the command.


All times are GMT -5. The time now is 11:03 PM.