I would like to know how to run a file in a case like this example:
I have two files in the paths:
/home/example/folder1/filewithname.sh
/home/example/folder2/filewithname.sh
I have both folders
added to PATH, how can I specify which filewithname.sh
I'm talking about?
Thanks in advance!
The directories listed in the PATH
variable will be searched in the order in which they are listed. When the given command is found, the search ends.
This means that if you added the two directories in the order that you show (folder1
before folder2
), then the command from folder1
will be used if you just say filewithname.sh
on the command line. The folder1
variant of the command effectively shadows the variant in folder2
.
If you want the other variant of command, you will have to access it using its path, i.e. as /home/example/folder2/filewithname.sh
, or via some equivalent pathname.
You may also create aliases for each of the commands so that you don't have to think about what order the directories are listed in $PATH
. For example,
alias c1=/home/example/folder1/filewithname.sh
alias c2=/home/example/folder2/filewithname.sh
This would allow you to use c1
and c2
to execute the two scripts.
You could put these alias definitions in your shell's initialization file (e.g. in ~/.bashrc
if you're using bash
, or in ${ZDOTDIR:-$HOME}/.zshrc
if you're using zsh
).
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments