Quantcast
Channel: VMware ESXi – The Wiert Corner – irregular stream of stuff
Viewing all articles
Browse latest Browse all 250

ESXi shell: appending the parent directory of a script to the path and starting a new shell, even if the script is symlinked

$
0
0

I needed a way to append the directory of a script to the path as all my tool scripts are in there, and I did not want to modify any profile scripts as these might be modified during ESXi upgrade.

First you need the full script filename through readlink then toe parent directory name through dirname:

Note there might be dragons with more symlinks or different shells:

I created the script below. It is not perfect, but for my situation it gets the job done.

If you do not start a new shell, then the export is lost as a new dash shell process is started for each script that runs from the terminal or console.

# cat /opt/bin/append-script-directory-to-path-and-start-new-shell.sh
#!/bin/sh
# Absolute path to this script, e.g. /home/user/bin/foo.sh
# echo "'$0'"
SCRIPT=$(readlink -f "$0")
# Absolute path this script is in, thus /home/user/bin
SCRIPTPATH=$(dirname "$SCRIPT")
# echo Appending to $PATH: $SCRIPTPATH
export PATH=$PATH:$SCRIPTPATH
sh

–jeroen


Viewing all articles
Browse latest Browse all 250

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>