Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
1. I was trying to execute a Bash Shell Script from any directory in the system. for this I need to make it available to execute anywhere in the system.

2. I also mistakenly added wrong path which I wanted to delete but its not happening.

Please help.

What I have tried:

1. I've added the path of the shell file in the $PATH variable. In my case -
PATH=$PATH:~/bin
. And when I tried to execute the file it is saying
Quote:
No such file or directory
.

2. Followed article - bash - Linux: Remove path from $PATH variable - Stack Overflow[^] but I could not remove in the single line shell command.
Posted
Updated 25-Aug-17 23:06pm

1. You should use the absolute path to your bin directory, or a defined variable such as $HOME, rather than the tilde (~).

2. You should post your question to the writer of the SO answer.
 
Share this answer
 
v2
Comments
Jochen Arndt 26-Aug-17 5:08am    
The tilde expands to the home directory of the current user which is effectively the same as $HOME.

But you are right: It must be an absolute path if the script should be also executed by other users.
Richard MacCutchan 26-Aug-17 5:10am    
And as usual OP does not really explain the problem.
B.Sudhir 27-Aug-17 3:25am    
Thank you for the solution this is helpful
To change the PATH environment variable you should export it (the export command will write it to the environment):
PATH=$PATH:~/bin
export PATH
Without the export command, the variable will be only set for the actual shell session but not for commands executed in that session or other shell sessions.

The simplest solution would be to save the script in a directory that is already searched. With Linux, there is a directory for such scripts: /usr/local/bin.

If it should be only executed by the user who created it, add the above to the shell settings for the user (~/.bash_profile or ~/.profile). With bash execute then the source command with the config file as argument to apply the settings (or log out and in again).

If you want to remove a path that has not been added to the global settings (e.g. /etc/environment) and the user settings (~/.bash_profile or ~/.profile) just log out and in again. Otherwise edit those files.
 
Share this answer
 
Comments
B.Sudhir 27-Aug-17 3:25am    
Thank you for the solution this is helpful

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900