If you are a UNIX nerd like me, you were probably jumping for joy the day Microsoft WSL was announced. Now you have access to lots of the UNIX goodies that your Mac and Linux friends have. I love myself a Bash shell and it’s one of the main reasons I prefer Mac and Linux or Windows. However, now I can make life easier for myself by using Bash on Windows. In this #QuickTip, we will be setting up Bash/WSL for Houdini on Windows. I’ll show you how to set up Windows to initialize the Houdini environment and have access to all the built-in Houdini tools through the Bash/WSL shell.
The Windows Subsystem for Linux (WSL) is a compatibility layer for running a Linux binary executable on Windows 10. So basically you have access to Bash and all the UNIX goodness including most command-line tools, utilities, and applications from Windows. If you are running the Creators Update, you have access to git, vim, nano, and gdb along with being able to invoke Windows applications from within Bash, and to invoke Linux applications from within Windows. Let us hope they continue to develop and improve on this. Now how can we take advantage of this with Houdini.
Setting up Bash/WSL for Houdini on Windows
There are a couple of things you need to do in order to get the WSL to work with Houdini. First, if you were to try a command like
hconfig or even
cd $HFS in a Bash shell, you will get an error right off the starting line. This is because the Houdini environment hasn’t been set up. In order to do this you have to modify your
$PATH to include the Houdini bin directory where all the Houdini specific commands are found. You can check your path by issuing the command
echo $PATH at the command prompt.
Setting Up Your Path
If you are not sure how to set up your path, I’ll give you a quick rundown on how to do this. It’s really just opening a text editor and adding a couple of lines. The tricky part is that Microsoft recommends not changing anything in the Linux sub-system via Windows. In other words, don’t open NotePad and edit your .profile file. You need to do this through one of the Bash editors. I prefer Vim but we can also do this with Nano which is a bit easier to use.
Open your Bash shell and at the prompt and type
nano .profile. The .profile is a hidden file so make sure you add the dot (.) before the name. We are going to add the Houdini bin directory to our
$PATH. Then we are going to write a tiny script to jump to this directory, source a Bash script that Side Effects has written and then jump back home. Navigate down using your arrow keys and you should see a line like the following:
# set PATH so it includes user's private bin directories PATH="$HOME/bin:$HOME/.local/bin
The first line is a comment. Lines that start with a hashtag denote a comment in Shell scripts. The second line is our
$PATH. Modify this second line to read like this:
# set PATH so it includes user's private bin directories PATH="$HOME/bin:$HOME/.local/bin:/mnt/c/Program\ Files/Side\ Effects\ Software/Houdini\ 16.5.300/bin:$PATH
A few thing to pay attention to here. There is a colon (:) right before our path to the Houdini bin directory. This is what separates the paths. If you are familiar with Windows Environment variables, this is equivalent to the semi-colon (;) to separate paths. Then notice the back slashes in the Houdini path. What we are doing here is escaping the spaces in the path. If you don’t escape the spaces, Bash will complain that the path does not exist. Another thing that is important is that the path to our directory uses forward slashes as opposed to the Windows convention to use back slashes for directory paths.If the back slashes are confusing, you can wrap the path within quotes. Also important, notice the path to the Houdini directory starts with
/mnt/ before following the regular C: drive and Program Files path. The WSL uses
/mnt/ path to “mount” the Windows C: drive and have access to its contents.
Last, you might be wondering why we are adding
$PATH to the end of the line right after our Houdini bin directory path. The reason is because since we are redefining the
$PATH variable, we want to make sure we include all the previous path locations that were originally defined. So we are saying please add this new path and also reattach the originals locations. Press Ctrl + o then Ctrl + x to save the changes and close the file. Close your shell and reopen it. If you don’t get any errors, you are golden. If you do get errors about paths not existing, double check there are no misplaced slashes, colons, and escape characters are in the right spot.
Houdini Stand Alone Utilities
Once you have your
$PATH set you can begin calling all the utilities Houdini provides from your Bash environment. Let’s do a quick example. I’m going to use the
iinfo utility to get some information from an image. One thing you need to keep in mind is that when you call the utilities, the command must include the .exe extension. So for example,
iinfo alone will not work. It needs to be
iinfo.exe. This is not a big deal since you would normally tab out the command and the full name with extension will be echoed.
Sourcing A Script
Now that we have our
$PATH all set up, it’s time to get the Houdini environment ready so every time you open up your shell, it’s ready to go. Open up your .profile back up if you closed it. We are going to write a few lines that take us to the Houdini installation directory, sources a Bash script Side Effects has written for us and then jumps back to our home directory. Make yourself a little space after the
$PATH line and type the following:
cd /mnt/c/Program\ Files/Side\ Effects\ Software/Houdini\ 16.5.300/ source houdini_setup cd
The first line uses the command
cd to navigate to the Houdini installation directory. Again, notice the back slashes and
/mnt/. Once in the directory, we use the
source command on the file houdini_setup_bash. The
source command is used to load any variables or functions into the current shell or environment. You will often see folks use the dot (.) instead of the full word
source. Both will work just fine. Finally, we navigate back to our home directory by using the handy shortcut of just
Save and close your file and now you are ready to rock. At least you hope so. Close your shell and reopen it. If all goes well, you should see the message “The Houdini 16.5.300 environment has been initialized” printed at the top of the command prompt. One thing you will most likely run into is an error that prints right after initializing the Houdini environment. Bash is complaining it can’t find a file specified in the houdini_setup script called hfilename. The file is there but remember what I mentioned about the .exe extension? That’s what is not allowing the script to find the file.
If you read the comments in the shell script on line 56, you will see Side Effects states that the environment variables in that section are no longer supported. So really, you can ignore the error. I prefer not to do that. It will keep me up at night. So we are going to fix it. All you have to do is add the extension to hfilename on line 63. First, you want to make a copy of the file and store away in your sock drawer just in case things go south. Once you have made a copy of the file for safe keeping and back up, just add .exe, save the file and you are done.
I definitely feel more productive having a Bash shell. Now, I want to say it’s not perfect. There are some oddities and some things just don’t work. For example, attempting to use the standalone Hscript interpreter from Bash does nothing. It starts, it just doesn’t do anything. I’ll keep messing with it and if I get it to work, I’ll pass the info along.