2

Check this page: https://www.veracrypt.fr/en/Uninstalling%20VeraCrypt.html

As the documentation mentioned:

...
To uninstall VeraCrypt on Linux, you have to run the following command as root: veracrypt-uninstall.sh.
...

When I entered the command sudo veracrypt-unistall.sh, in home directory, it did what it supposed to do (uninstalling veracrypt). However as far as I know, if we want to run a shell script, we must be in the same directory as the script.

Now here, there is two possibilities:
One is that the script was already in ~, or
Two is that shell script (veracrypt-uninstall.sh) was a command itself stored in somewhere like: /bin or /usr/bin.

On the other hand I didn't find any shell script named 'veracrypt-uninstall.sh' in my home directory, so how?

Update:
$ echo $PATH
Output: /home/linuxbrew/.linuxbrew/bin /home/linuxbrew/.linuxbrew/bin /home/linuxbrew/.linuxbrew/sbin /usr/local/bin /usr/local/sbin /usr/bin /usr/sbin

  • 1
    What does your title have to do with the rest of the question? As for "if we want to run a shell script we must be in the right directory consisting the script within itself": https://unix.stackexchange.com/questions/162134/how-to-execute-a-bash-script-without-typing – muru Nov 20 '18 at 10:26
  • @muru I thought it's a global command (environmental variable), I'm a newbie to Linux and command-line world, I'm sorry if I did any mistake. – Mohammad Hossein Nov 20 '18 at 10:40
  • A command is not an environment variable. See https://unix.stackexchange.com/questions/91282/what-exactly-is-an-environment-variable – muru Nov 20 '18 at 10:41
  • I updated my answer, to reflect the new title, and added some detail. – ctrl-alt-delor Nov 20 '18 at 10:57
  • I would expect the output of echo $PATH, to have the fields delimited(separated), by :s (not spaces). – ctrl-alt-delor Nov 20 '18 at 10:59

2 Answers2

4

Yes it can be a global command.

There is no difference: an executable is an executable. It dose not matter what language an executable is written in (some languages can do some things that others can not, but they are still executables). In Unix executable should not have a file extension: the .sh at the end is just part of the file, nothing special. However having it tells the caller what language it was written in, and makes it impossible to change the language, without updating all callers.

Scripts and programs are searched for by looking in the $PATH variable. type echo $PATH to get a list of where the system searches (sudo echo $PATH, for where it searches when you are root). It is the same place as when searching for non-scripts (as they are all executables).

Running local programs (in the same directory)

To run something that is in same directory you need to do ./«script-name», unless someone has, dangerously, added . to the PATH.

  • The .sh filename suffix on scripts could serve as a way of adding a "namespace" to local/personal scripts. I could have a getmail.sh script that does not collide with an already existing getmail executable, for example. – Kusalananda Nov 20 '18 at 11:57
  • If not in $PATH then it can not collide. However the namespace idea is good. So choose a good name for your namespace. Such as My_… Don't rely on an artefact of something else, especially when that something else is bad practice. [This reminds me of complaints of LED traffic lights: ”But they don't melt the snow.” We did not, initially, realise that we were depending on the in-efficiency of the old design. So a heater was added, with a thermostat. Now the LED lights did the same, but with less power needed.] – ctrl-alt-delor Nov 20 '18 at 12:10
0

Not sure which flavor of Gnu/linux you are on, but here are some generic handy helpers.

echo $PATH - will give you all of the paths that are being looked at for scripts and binaries. keep in mind running something under sudo is doing so as a different person so "sudo echo $PATH" may have different results.

On some OSs , root has access to commands that users do not.

whereis veracrypt-unistall.sh and sudo whereis veracrypt-unistall.sh may show you the path if known, also some systems have the which command.

which veracrypt-unistall.sh

if you have top or htop installed, having it open while the script is running will allow you to see the full path in the command column

  • I don't think this answers the question of running shell scripts from PATH (or otherwise out of the current directory) – ilkkachu Nov 20 '18 at 10:48