In https://github.com/elastic/elasticsearch/blob/master/distribution/src/bin/elasticsearch-cli,
when we
source "`dirname "$0"`"/elasticsearch-env
we cd in $ES_HOME changing the pwd. However, the dirname commands in the following
for additional_source in "${additional_sources[@]}"
do
source "`dirname "$0"`"/$additional_source
done
will have an output that is always relevant to the current dir from where the user ran the cli command.
The combination of these two mean, that the source command will try to source a file, the path of which will be the concatenation of $ES_HOME and the dir from where the user ran the cli command. This will only work when the user runs the command from $ES_HOME. Example output from @pheyos who raised this:
robert@elastic-ro:~/es_versions/700_bc1/elasticsearch-7.0.0/bin$ ./elasticsearch-setup-passwords interactive
./elasticsearch-cli: line 10: ./x-pack-env: No such file or directory
./elasticsearch-cli: line 10: ./x-pack-env: No such file or directory is because the pwd at that time is $ES_HOME and not $ES_HOME/bin
In https://github.com/elastic/elasticsearch/blob/master/distribution/src/bin/elasticsearch-cli,
when we
we cd in
$ES_HOMEchanging the pwd. However, thedirnamecommands in the followingwill have an output that is always relevant to the current dir from where the user ran the cli command.
The combination of these two mean, that the
sourcecommand will try to source a file, the path of which will be the concatenation of$ES_HOMEand the dir from where the user ran the cli command. This will only work when the user runs the command from$ES_HOME. Example output from @pheyos who raised this:./elasticsearch-cli: line 10: ./x-pack-env: No such file or directoryis because the pwd at that time is$ES_HOMEand not$ES_HOME/bin