The Wiert Corner – irregular stream of stuff

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

  • My badges

  • Twitter Updates

    • RT @SwiftOnSecurity: To be fair, anyone who's tried to use VMware's website would probably rather see it deleted 43 minutes ago
    • RT @mmeeuw: “Je mag Joost Eerdmans niet vergelijken Anton Mussert en JoostAnnabel21 niet met de NSB, daar kunnen ze niet tegen, dan worden… 44 minutes ago
    • RT @roosvonk: Omdat enkele fabrieken van Tatasteel zo verouderd zijn dat ze extra veel vervuilen, hoeven ze niet te voldoen aan de strenge… 48 minutes ago
    • RT @zaagvis: Mijn moestuin is een kilometer van huis en ja ik ga altijd met de auto omdat ik zoveel mee moet slepen, nu dacht ik, als ik ee… 50 minutes ago
    • @Suuzer83 War heftig. Ik duim dat het stopt en wns je veel sterkte. 🤗 52 minutes ago
  • My Flickr Stream

  • Pages

  • All categories

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

    Join 2,733 other followers

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 )

Twitter picture

You are commenting using your Twitter 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: