Score:0

Adding simple shortcut on the terminal, the right way

gb flag

I am trying to add folder to PATH variable (for specific user only).

so to ~/.bashrc i have added

export PATH=$PATH:/home/username/Tools/scripts/

within this folder i am having scripts and some shortcuts to other programs (for example: firefox.sh)

When i open new terminal, path variable is correct but when i try to do "sh firefox" i get "No such file".

I want to be able to execute for this user any *.sh script from any folder from terminal What am i doing wrong?

Raffa avatar
jp flag
That is not how it works
Score:1
jp flag

Scripts in your search path should have unique names(different from other system commands including shell builtins) i.e. avoid names such as firefox, vlc, nano, echo, cd, test, sudo ... etc.

Scripts in your search path are run by filename(including extensions like e.g. .sh if used) without specifying the shell interpreter(these are executables that take their arguments as script files with full path or script command strings but not an executable/scriptfile in your path that you call by just its filename) before it but rather include a shebang in it i.e. not like this:

sh scriptname

But rather like this:

scriptname

Scripts in your search path need to include a shebang(The first line in the script that tells what interpreter should be used to run the script) that looks like this:

#!/bin/bash

or this:

#!/bin/sh

or even this:

#!/bin/python3

and so on.

Scripts in your search path need to be made executable first like so:

chmod +x /full/path/to/scriptname

That's how they work.

Score:0
gb flag

bash and sh are different shells. I believe ~/.bashrc would not be read by sh. Try putting your additional to the path in ~/.profile which should get read by all shells.

Additionally, you wrote that you script is called firefox.sh so you would also need to reference it by sh firefox.sh - but this still might not work because the search path is only evaluate for executables, while in this case you try to load a script with sh and are not directly executing it.

Try

sh `which firefox.sh`

to first resolve the path. This would also fork if firefox.sh has the mode "x" (chmod +x firefox.sh)

Raffa avatar
jp flag
An exported path with `export` will be available to `sh`(be it linked to `dash` or else*) and to any other installed shell if at least the containing file is sourced at least once per login.
gb flag
Yes, true - if `sh` is called from a `bash` this would work.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.