2 folders added to PATH contain different files with the same name

S. DRE Works

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!

Kusalananda

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to delete 2 files with the same name from different folders?

PyCharm Import files with same name in different folders

Find files with same name in different folders

Merge files with same name in different folders

Moving several files to different folders with same name

List all files under different folders with same name

Move files with same name in different folders to one folder

Separate files by name into different folders

Python script to copy different files from one folder to different sub-folders.with same name as file name

How to differentiate files with same name with different extension from two different folders? Python

Batch command move png files to folders same name files and folders

Return the absolute path to files from different folders

Windows Phone Classes with same name but different folders

Delete content of folders with same name in different subdirectories

Android DataBinding & MVVM - Using same name for layout files in different layout folders

load multiple files from different folders with same file name in bash-scipt

Configure nginx to use files and folders with the same name

rename the files with same names in different folders

Merging 2 files with the same name in 2 different branches in git

Find only those folders that contain a File with the same name as the Folder

How to mention once to ignore 2 folders with same name from different directories using gitignore?

Show the full path and name of all files that contain keywords in their name

Java - Two classes, same name, same package but in different folders

Linux find files and folders based on name length but output full path

How to solve function overloading on Octave from different folders but with the same name?

Asset Catalog: Access images with same name in different folders

Delete file with same name contained in different sub-folders

Read Multiple raster with the same name contained in different folders

Search for text in files of same name in multiple folders of various depths