LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 11-02-2012, 03:00 AM   #1
Alpha90
Member
 
Registered: Jul 2012
Posts: 45

Rep: Reputation: Disabled
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.
 
Old 11-02-2012, 03:51 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,528
Blog Entries: 27

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
How why are you using eval in conjunction with the changed .bash_profile? The source command is more appropriate for testing.
 
Old 11-02-2012, 03:52 AM   #3
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 651

Rep: Reputation: 269Reputation: 269Reputation: 269
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?
 
Old 11-02-2012, 04:46 PM   #4
Alpha90
Member
 
Registered: Jul 2012
Posts: 45

Original Poster
Rep: Reputation: Disabled
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
 
Old 11-02-2012, 05:31 PM   #5
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Gentoo
Posts: 15,437
Blog Entries: 2

Rep: Reputation: 4000Reputation: 4000Reputation: 4000Reputation: 4000Reputation: 4000Reputation: 4000Reputation: 4000Reputation: 4000Reputation: 4000Reputation: 4000Reputation: 4000
Please post the exact command you typed in, the exact error message you got and the changes you made to your Bash configuration.
 
Old 11-02-2012, 08:50 PM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
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"

Last edited by shivaa; 11-02-2012 at 08:51 PM.
 
Old 11-03-2012, 01:53 PM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
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.
 
Old 11-03-2012, 08:06 PM   #8
Alpha90
Member
 
Registered: Jul 2012
Posts: 45

Original Poster
Rep: Reputation: Disabled
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 ?
 
Old 11-03-2012, 08:16 PM   #9
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,646

Rep: Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951
Quote:
Originally Posted by Alpha90 View Post
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"
 
Old 11-03-2012, 09:54 PM   #10
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
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
 
Old 11-04-2012, 10:16 AM   #11
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
List file with path from current working directory Stragonian Linux - Newbie 3 10-09-2012 09:39 AM
Add the xyz directory to your path (what path?) Eerie Linux - Newbie 3 06-06-2012 04:48 PM
List file names in a directory WITHOUT the path dexus Linux - Newbie 13 06-13-2009 07:22 PM
Find a file path and directory path ak.lokesh Linux - Newbie 3 02-19-2009 12:37 PM


All times are GMT -5. The time now is 03:46 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration