Saturday, May 4, 2024
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 3609  / 2 Years ago, sat, february 12, 2022, 11:50:50

I had an executable script on my ubuntu located on ~/project/ directory and I tried to add that path to /etc/environment . So , I edit the path to this PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:~/project/" . Then , I logout and login back , open the terminal as su and run the command to execute my script on that folder but the result is command not found.



Then, I change the path in /etc/environment to PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/r0xx4nne/project/" and voila it works.Now i can run the executable script inside ~/project/ without fail under su command.



My question is , what's the difference between ~/project and /home/r0xx4nne/project when it comes in case of creating a path in /etc/environment ?



Why it happened to be like this? I am a newbie and I just want to know more . Thanks for any reply .


More From » environment-variables

 Answers
2

In the shell, ~/project/ is expanded to /home/yourusername/project in most circumstances. This is called tilde expansion.



If you put



PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:~/project/


(note, without the quotes) in ~/.profile. Your PATH will be set correctly, because ~/.profile is interpreted by a shell when you log in. /etc/environment (and it's user-specific ~/.pam_environment) is not interpreted by a shell. It is read by the pam_env module during login, but it only accepts NAME=VALUE pairs and no expansions (like $var or ~/ or $(command) etc.) will be done on the VALUE.


[#37501] Sunday, February 13, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mugustered

Total Points: 193
Total Questions: 123
Total Answers: 108

Location: Bermuda
Member since Wed, Mar 22, 2023
1 Year ago
;