DEV Community

Cover image for How to run Obsidian CLI on WSL
Srinjoy Santra
Srinjoy Santra

Posted on

How to run Obsidian CLI on WSL

My preferred dev terminal nowadays is WSL2 of Ubuntu. After installing Obsidian CLI on windows, I could not figure out how to run the new cli tool on WSL.

The following instruction does not work in WSL

obsidian help
Enter fullscreen mode Exit fullscreen mode

However, the same works perfectly fine on Powershell or command prompt as the executable path is already added to environment variables path.

Usually windows path is imported into WSL.

echo $PATH
Enter fullscreen mode Exit fullscreen mode

If not enable it in

nano ~/.wslconfig
Enter fullscreen mode Exit fullscreen mode

Add

[interop]
appendWindowsPath=true
Enter fullscreen mode Exit fullscreen mode

then restart wsl.

wsl --shutdown
Enter fullscreen mode Exit fullscreen mode

Once your app is in the Windows PATH, you can run it by:

obsidian.exe
Enter fullscreen mode Exit fullscreen mode

If you try running on WSL (in my case Ubuntu)

obsidian.exe help
Enter fullscreen mode Exit fullscreen mode

the output appears all garbled now.

obsidian cli on linux

Reason

Windows executables output \r\n (CRLF) line endings, while Linux terminals expect \n (LF). The extra carriage return (\r) causes the cursor to jump back to the start of the line, producing messy output.

Quick Fix

Pipe the output through tr -d '\r' to strip carriage returns:

obsidian.exe 2>&1 | tr -d '\r'
Enter fullscreen mode Exit fullscreen mode

Permanent Fix: Create a Wrapper Script

Instead of typing the pipe every time, create a wrapper script:

mkdir -p ~/bin
Enter fullscreen mode Exit fullscreen mode

Create ~/bin/obsidian with the following content:

#!/bin/bash
obsidian.exe "$@" 2>&1 | tr -d '\r'
Enter fullscreen mode Exit fullscreen mode

Make it executable and add ~/bin to your PATH:

chmod +x ~/bin/obsidian
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Now just run obsidian instead of obsidian.exe — clean output, every time.

Output after removing carriages

Top comments (0)