bash script displaying directories in order they are searched

linux bash shell path

39 просмотра

1 ответ

16 Репутация автора

Hi everyone I'm currently having a difficult time writing a command in a bash script file that when it runs will display the directories in my search path in the order they appear.

I've tried the following:

SEARCH_PATH=$( $PATH | tr ':'  '\n')

but once I execute the file it comes back with nothing

I've also tried this:

BASEDIR=$(dirname $0)

to be honest I found the above code from elsewhere and was confused to what dirname is and how the arguement $0 affects it

Any help is appreciated!

Автор: Nathan Barnes Источник Размещён: 08.11.2017 10:45

Ответы (1)

2 плюса

472194 Репутация автора

You're missing the echo command in your first command:

search_path=$(echo "$PATH" | tr ':' '\n')
echo "$search_path"

There's not really any reason to use the variable, you can just do:

echo "$PATH" | tr ':' '\n'

Your code was trying to use the value of $PATH as a command to execute.

You should also avoid using uppercase names for shell variables, the convention is that these names are reserved for environment variables.

Автор: Barmar Размещён: 08.11.2017 10:50
Вопросы из категории :