The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,224 other subscribers

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

Posted by jpluimers on 2021/10/26

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/
# Absolute path to this script, e.g. /home/user/bin/
# echo "'$0'"
SCRIPT=$(readlink -f "$0")
# Absolute path this script is in, thus /home/user/bin
# echo Appending to $PATH: $SCRIPTPATH


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: