LinuxQuestions.org
Visit Jeremy's Blog.
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 10-26-2009, 11:30 PM   #16
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,330

Rep: Reputation: 227Reputation: 227Reputation: 227

Quote:
Originally Posted by catkin View Post
You can have "." in $PATH.
thanks for the tip.
 
Old 10-26-2009, 11:41 PM   #17
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,228

Rep: Reputation: 128Reputation: 128
Does ./program2.sh work while in the directory that program2.sh exists in?
 
Old 10-27-2009, 12:32 AM   #18
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by r3sistance View Post
Does ./program2.sh work while in the directory that program2.sh exists in?
Yes
 
Old 10-27-2009, 02:17 AM   #19
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by pinga123 View Post
How to add into path variable
If you want the shell to search the current directory for the executable before all the other directories (this is useful if you want to replace a system command -- for example, you could write a script called ls and it would be run instead of /bin/ls)
Code:
export PATH=".:$PATH"
If you want the shell to search the current directory for the executable after all the other directories (safer -- in case you accidentally create an executable with the same name as an existing executable and run it accidentally with unexpected effects)
Code:
export PATH="$PATH:."
Not recommended to have . in root's $PATH.
 
Old 10-27-2009, 02:06 PM   #20
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,228

Rep: Reputation: 128Reputation: 128
If this is a script you want to be able to call from anywhere, one possibility is the following command

ln /bin/program2 <pathtoprogram2>/program2.sh

This would place a Symbolic link in /bin to your script, this is just if you wanted to be able to run it from anywhere, personally I wouldn't advise this for most generallised scripts however. You could add a directory to path for little scripts like that... as './script' works however, it makes it appear strange that 'sh script' doesn't work...
 
Old 10-27-2009, 11:43 PM   #21
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by catkin View Post
If you want the shell to search the current directory for the executable before all the other directories (this is useful if you want to replace a system command -- for example, you could write a script called ls and it would be run instead of /bin/ls)
Code:
export PATH=".:$PATH"
If you want the shell to search the current directory for the executable after all the other directories (safer -- in case you accidentally create an executable with the same name as an existing executable and run it accidentally with unexpected effects)
Code:
export PATH="$PATH:."
Not recommended to have . in root's $PATH.
I didnt get the last line.why?

Quote:
Not recommended to have . in root's $PATH.

Last edited by pinga123; 10-27-2009 at 11:47 PM.
 
Old 10-27-2009, 11:51 PM   #22
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Any way i think i have got Answer to my question.

I wanted to run my script in vi using :!<program-name> syntax
I have exported path to "$PATH:."
I m logging into system using root and now able to execute the file by just using its name.

Is there anything wrong in above mentioned method?
will it impact system working in any wrong manner?
 
Old 10-28-2009, 12:14 AM   #23
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,228

Rep: Reputation: 128Reputation: 128
having . in your path will mean you could possible get into situtations where commands in current directory will override those in other directories, assume for a moment you have a script file called cd that you use to mount the cd-rom drive, if you had . in path and you went to use the cd(change directory) command, it wouldn't work as the script file to mount a cd-rom could potentially take priority, it's not an end game situtation, you could just rename the script or remove it...

This was just an example, I am not sure if you can do this with cd as cd is actually built into bash... however not many things are (IE ls for example comes from /bin/ls)

Last edited by r3sistance; 10-28-2009 at 12:17 AM.
 
Old 10-28-2009, 12:37 AM   #24
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by r3sistance View Post
having . in your path will mean you could possible get into situtations where commands in current directory will override those in other directories, assume for a moment you have a script file called cd that you use to mount the cd-rom drive, if you had . in path and you went to use the cd(change directory) command, it wouldn't work as the script file to mount a cd-rom could potentially take priority, it's not an end game situtation, you could just rename the script or remove it...

This was just an example, I am not sure if you can do this with cd as cd is actually built into bash... however not many things are (IE ls for example comes from /bin/ls)
I have exported path as "$PATH:." and not ".:$PATH" so i think cd .. will get you to parent directory rather than mounting a cd-rom drive as it will first check the path and then the current directory.
However i m a newbie and cant confirm on the same.Any expert please suggest if i m wrong.
 
Old 10-28-2009, 12:34 PM   #25
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by pinga123 View Post
I have exported path as "$PATH:." and not ".:$PATH" so i think cd .. will get you to parent directory rather than mounting a cd-rom drive as it will first check the path and then the current directory.
However i m a newbie and cant confirm on the same.Any expert please suggest if i m wrong.
Yes -- you've got it right.

According to The Linux Documentation Project's security HOWTO you should never have . in root's $PATH. You could follow that advice and still have the convenience you want by following r3sistance's advice although I would change it slightly to
Code:
cd /usr/local/bin
ln -s <pathtoprogram2>/program2.sh program2.sh
/usr/local/bin is more appropriate for locally written programs (see the Linux Filesystem Hierarchy); a symbolic link (created by the -s option on ln) will work even if the target is on another file system; the existing file must be given before the symbolic link name; it's more transparent if the symbolic link name is the same as the file it links to.
 
Old 10-30-2009, 10:54 PM   #26
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
But then i have to make symbolic links for every program i write .

I usually add . in path when i m troubleshooting some scripts to make their execution simpler.
Please explain whats the harm in putting . in path variable.
 
Old 10-31-2009, 10:55 AM   #27
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by pinga123 View Post
Please explain whats the harm in putting . in path variable.
The usual explanation is "Including the current working directory '.' (dot) or other writeable directory in root's executable path makes it likely that an attacker can gain superuser access by forcing an administrator operating as root to execute a Trojan horse program". This is unlikely to happen on a system used only by yourself when the . directory comes at the end of $PATH. Still safer not to do it. Alternatively you could put the current directory in $PATH temporarily when developing scripts
Code:
export PATH="$PATH:$(pwd)"
I use ./myscript.sh; the ./ prefix is not onerous, especially using command recall.
 
  


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
gcc will not execute, responds with 'no such file or directory' and 'no input file' nckeecho Ubuntu 9 07-24-2016 01:04 PM
how to execute a script file? Have file/directory not found error sirius57 Linux - Software 2 11-21-2007 11:43 PM
cannot execute binary file on a selfx file brucifer Linux - Software 4 03-21-2006 04:44 AM
execute .el file balloon Linux - Software 2 11-16-2004 06:02 AM
how to execute a file malik Linux - Software 1 06-10-2004 08:53 PM


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

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration