bash script displaying directories in order they are searched
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') echo $SEARCH_PATH
but once I execute the file it comes back with nothing
I've also tried this:
BASEDIR=$(dirname $0) echo $BASEDIR
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
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