LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-24-2015, 08:57 AM   #1
Toroso
Member
 
Registered: Mar 2015
Distribution: Mint Linux 17.1 64 Xfce
Posts: 31

Rep: Reputation: 4
Symbolic links


I want to understand symbolic links. In this example:

ln -s /bin/bash /bin/sh

Is it correct that whenever 'sh' is encountered in a script or whatever, that 'bash' is the code ultimately executed?
 
Old 03-24-2015, 09:28 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Yes but ONLY if /bin is the first location it finds "sh" in as determined by PATH.

The PATH variable determines locations to search. So if you do "echo $PATH" and it shows "/bin:/usr/bin:/home/myhome" and you search for "sh" it will will find /bin/sh first and use it even if /usr/bin/sh and /home/myhome/sh exist.

If however you had "/usr/bin:/bin:/home/myhome" in PATH it would find the one in /usr/bin first and ignore the one in /bin.

Of course if you type "/bin/sh" that is an absolute reference and it would ignore PATH.
 
1 members found this post helpful.
Old 03-24-2015, 09:55 AM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Also, some utilities like bash and busybox will look at how it was called and alter its behavior as necessary. For example, if you symlink /bin/bash to /bin/sh and then call /bin/sh, while /bin/bash is the executable that's ultimately being run, it very well might see that you called it as "/bin/sh" and alter its behavior to reflect sh's limited command set.
 
2 members found this post helpful.
Old 03-24-2015, 10:35 AM   #4
Toroso
Member
 
Registered: Mar 2015
Distribution: Mint Linux 17.1 64 Xfce
Posts: 31

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by MensaWater View Post
Yes but ONLY if /bin is the first location it finds "sh" in as determined by PATH.

The PATH variable determines locations to search. So if you do "echo $PATH" and it shows "/bin:/usr/bin:/home/myhome" and you search for "sh" it will will find /bin/sh first and use it even if /usr/bin/sh and /home/myhome/sh exist.

If however you had "/usr/bin:/bin:/home/myhome" in PATH it would find the one in /usr/bin first and ignore the one in /bin.

Of course if you type "/bin/sh" that is an absolute reference and it would ignore PATH.
Thank you both, that helps a lot.

---------- Post added 03-24-15 at 11:35 AM ----------

Quote:
Originally Posted by suicidaleggroll View Post
Also, some utilities like bash and busybox will look at how it was called and alter its behavior as necessary. For example, if you symlink /bin/bash to /bin/sh and then call /bin/sh, while /bin/bash is the executable that's ultimately being run, it very well might see that you called it as "/bin/sh" and alter its behavior to reflect sh's limited command set.
Thanks
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Symbolic links Vs Hard links sulekha Linux - General 2 10-02-2008 07:03 AM
Symbolic Links SBN Linux - Newbie 5 08-09-2007 05:48 AM
Symbolic Links suavecu Linux - Software 1 01-11-2006 10:04 PM
Symbolic links pdstatha Programming 1 04-08-2002 09:50 PM
symbolic links winger Linux - General 5 04-06-2002 05:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:53 AM.

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
Open Source Consulting | Domain Registration