LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 04-06-2021, 05:50 AM   #1
amikoyan
Member
 
Registered: Mar 2021
Distribution: Slackware64 -current
Posts: 318

Rep: Reputation: 171Reputation: 171
edit to .bashrc makes other directories executable, not just ~/bin


I added this to my .bashrc

Code:
. /etc/profile
PATH=$PATH:~/bin
expecting it would just cause ~/bin to allow files to be executed. However, it has allowed me to execute files in other directories located in the home directory.

I also tried adding this to .bashrc (not at the same time):
Code:
export PATH=~/bin:"$PATH"
with the same result.

I just want ~/bin to be able to allow files to be executed

Last edited by amikoyan; 04-06-2021 at 05:53 AM.
 
Old 04-06-2021, 05:59 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,484

Rep: Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556
Execute permissions are nothing to do with the PATH

Execute permissions are based on whether or not the individual file has execute for owner/group/world
 
Old 04-06-2021, 06:00 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,047

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
you need to check the meaning of PATH: https://en.wikipedia.org/wiki/PATH_(variable)
That is just a search path, it does not allow or deny execution.

So would be nice to explain better what do you need, probably an example ....
 
Old 04-06-2021, 06:09 AM   #4
amikoyan
Member
 
Registered: Mar 2021
Distribution: Slackware64 -current
Posts: 318

Original Poster
Rep: Reputation: 171Reputation: 171
Sorry, my fault, I am not quite sure what I am asking.

I only want the script to run when I type its filename when it is located in ~/bin.

If the script is anywhere else I would expect to have to type ./filename.

With the text added to .bashrc I just type the filename and the script runs from any directory in ~/.

I hope I have explained my intentions more clearly
 
Old 04-06-2021, 06:34 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,047

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
that's why you should give us an example, what did you try exactly....
 
Old 04-06-2021, 07:01 AM   #6
amikoyan
Member
 
Registered: Mar 2021
Distribution: Slackware64 -current
Posts: 318

Original Poster
Rep: Reputation: 171Reputation: 171
There is a bash script located in ~/test. It is called hello_world

Before editing .bashrc as shown in the posts above
Code:
mik@linuxbox:~/test$ hello_world
bash: hello_world: command not found
Which is expected

After editing .bashrc as shown in the posts above

Code:
mik@linuxbox:~/test$ hello_world
Hello World!
Which is not expected, as I want only scripts located in ~/bin to do this.

Why is the shell searching my ~/test directory for executable files when I only want it to search ~/bin for executable files?
 
Old 04-06-2021, 07:04 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,047

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
how is your PATH variable set ? (can you post the result of: echo $PATH)
 
Old 04-06-2021, 07:06 AM   #8
amikoyan
Member
 
Registered: Mar 2021
Distribution: Slackware64 -current
Posts: 318

Original Poster
Rep: Reputation: 171Reputation: 171
Code:
 echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/games:/sbin:/usr/sbin:/usr/lib64/kde4/libexec:/usr/lib64/qt/bin:/usr/share/texmf/bin:/home/mik/bin
 
Old 04-06-2021, 07:11 AM   #9
Alien Bob
Slackware Contributor
 
Registered: Sep 2005
Location: Eindhoven, The Netherlands
Distribution: Slackware
Posts: 8,559

Rep: Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106
My guess is that you have a copy of that file in ~/bin/hello_world and that one gets executed.
 
1 members found this post helpful.
Old 04-06-2021, 07:22 AM   #10
amikoyan
Member
 
Registered: Mar 2021
Distribution: Slackware64 -current
Posts: 318

Original Poster
Rep: Reputation: 171Reputation: 171
Alien Bob, you are correct, there is a copy of hello_world in ~/bin.

I have deleted it. But then when I cd to ~/test this is what happens:

Code:
mik@linuxbox:~/test$ ls
c-scripts/  hello_world*  hello_world~*
mik@linuxbox:~/test$ hello_world
bash: /home/mik/bin/hello_world: No such file or directory
 
Old 04-06-2021, 07:28 AM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,047

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
you can use the command which to check where it was actually found.
You might want to check the thread as solved.
 
1 members found this post helpful.
Old 04-06-2021, 07:32 AM   #12
Petri Kaukasoina
Senior Member
 
Registered: Mar 2007
Posts: 1,938

Rep: Reputation: 1568Reputation: 1568Reputation: 1568Reputation: 1568Reputation: 1568Reputation: 1568Reputation: 1568Reputation: 1568Reputation: 1568Reputation: 1568Reputation: 1568
Code:
help hash
hash -t hello_world
hash -r
 
2 members found this post helpful.
Old 04-06-2021, 07:32 AM   #13
Alien Bob
Slackware Contributor
 
Registered: Sep 2005
Location: Eindhoven, The Netherlands
Distribution: Slackware
Posts: 8,559

Rep: Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106
Quote:
Originally Posted by amikoyan View Post
Alien Bob, you are correct, there is a copy of hello_world in ~/bin.

I have deleted it. But then when I cd to ~/test this is what happens:

Code:
mik@linuxbox:~/test$ ls
c-scripts/  hello_world*  hello_world~*
mik@linuxbox:~/test$ hello_world
bash: /home/mik/bin/hello_world: No such file or directory
This is a Bash behavior, it remembers (or 'hashes) the path from where it started your programs.
Try
Code:
$ type hello_world
You should get something like:
Code:
hello_world is hashed (/home/mik/bin/hello_world)
To remove this hash so that Bash no longer remembers the path where it found the program:
Code:
$ hash -d hello_world
$ hello_world
bash: /home/mik/bin/hello_world: No such file or directory
 
4 members found this post helpful.
Old 04-06-2021, 07:36 AM   #14
amikoyan
Member
 
Registered: Mar 2021
Distribution: Slackware64 -current
Posts: 318

Original Poster
Rep: Reputation: 171Reputation: 171
Thank you to all who helped, especially for the explanation about hashing, Alien Bob.

Also to Petri Kaukasoina, who also mentioned hash.

Last edited by amikoyan; 04-06-2021 at 12:56 PM.
 
Old 04-06-2021, 12:33 PM   #15
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
Quote:
Originally Posted by Alien Bob View Post
This is a Bash behavior, it remembers (or 'hashes) the path from where it started your programs.
Try
Code:
$ type hello_world
You should get something like:
Code:
hello_world is hashed (/home/mik/bin/hello_world)
To remove this hash so that Bash no longer remembers the path where it found the program:
Code:
$ hash -d hello_world
$ hello_world
bash: /home/mik/bin/hello_world: No such file or directory
I've been using Linux for close to 20 years and I never knew about this! Thanks for teaching me something new! For those interested in learning more, see this StackExchange answer.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] /etc/bashrc ,dircolors and /root/.bash_profile ,/.bashrc not exist in LFS-7.5(sec9.3) jaassi Linux From Scratch 2 09-20-2014 05:04 PM
~/.bashrc, /etc/bash.bashrc files not read? Tachtory Slackware 3 01-04-2014 12:25 AM
echo $PATH = /home/g3rc4n/bin:/usr/local/bin:/usr/bin:/bin:/usr/games ? i_heart_pandas Linux - Software 7 09-18-2009 08:33 AM
Setting path: /etc/profile, /etc/bashrc or ~/.bashrc Swakoo Linux - General 1 08-07-2007 10:59 PM
sudo /usr/bin/chroot /home/chroot /bin/su - xxx| /bin/su: user xxx does not exist saavik Linux - General 3 07-04-2007 10:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 11:29 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