Equivalent to “source” in OpenBSD? Python Linux/Unix

Are you getting equivalent to “source” in OpenBSD? In this post, I will tell you how you resolve these issues quickly.

Are you attempting to open a python3 virtual environment that I’ve created with VirtualBox on a Linux environment? Are you getting the below error?

ksh: source: not found

Quickly Resolve Equivalent to “source” in OpenBSD

You are currently logged in with the Forsyth PD Korn shell, which is the default login shell on OpenBSD. The source command is not available in the PD Korn shell.

The source built-in command is only available in a few shells, and it is not always available. The command is the one you’re looking for, to be precise is “.”.

In contrast to the source keyword that is available in bash, this keyword is not included in the POSIX standard. Instead, you can make use of below command.

. myVenv/bin/activate
Equivalent to "source" in OpenBSD? Python Linux/Unix

What is the difference between ‘.’ and ‘source’ in shells?

. is the Bourne and POSIX shell command while source is the C-Shell command.

Some Bourne-shell derivatives like bashzsh and most implementations of ksh also have a source the command which is generally an alias for . – however, it may behave slightly differently (e.g. in zsh and ksh).

For bash, . and source behave the same, but their behavior is affected by whether they are run in POSIX mode or not¹.

POSIX requires that the . the command exits the shell process² if it can’t open the file for reading and requires that the file be found through a search of the directories in $PATH if the provided path doesn’t contain a /.

csh‘s source interprets the argument as a path, and never looks the file up in $PATH.

bash . and source behave as POSIX requires when in POSIX mode and as dish’s source when not, that is they don’t exit the script if they fail to open the file for reading (same as a command .) and look up the file in $PATH and the current directory if the provided path doesn’t contain a /.

zsh . behaves as POSIX requires, while source looks in the current directory first and then $PATH (even in csh emulation) when the argument doesn’t contain a /. (see info zsh . and info zsh source for details). If . or source fail to find/open the file, that only aborts the shell when in POSIX mode (sh emulation) though.

AT&T ksh’s source doesn’t exit the shell either but doesn’t look for the file in the current directory.

All in all, in Bourne-like shells (though not the Bourne shell that doesn’t have a command builtin), if you want consistent behaviour, you could do

command . /path/to/the-file-to-source || handle-error

Wrap Up

Hope I was able to solve your issue. If you are still having any issues then please provide your comment below so that I can look into it and provide you the resolution as soon as possible.

If you liked our answer then please follow us on FacebookTwitter and Subscribe to our Newsletter to join a great community of developers around the world. Let us know the questions and answer you want to cover in this blog.

Further Read:

  1. How to Make python3.7 default on Unix/Linux
  2. Stop/Kill a process from the command line after a certain amount of time Python

Leave a Reply

Your email address will not be published. Required fields are marked *