How to Start Windows Terminal and Run Bash Command Immediately

Abstract: Run a Bash command immediately in Windows Terminal using the wt executable with the --wsl flag and bash -c syntax.

Created: 2026-09-10 by
You can start Windows Terminal and execute a Bash command immediately by using the wt executable with the --wsl flag followed by your specific command string. This approach leverages Windows Terminal's native ability to spawn new panes or windows directly into a Linux subsystem environment, allowing for automated scripting or quick access to development tools without manual navigation through the user interface.

Understanding the WT Executable

The primary tool for this task is the wt command-line utility, which is installed alongside Windows Terminal. It serves as a launcher that can open new tabs, split panes, or entire windows based on JSON profiles or direct arguments. When interacting with Ubuntu or other WSL distributions, you must specify the profile name or use flags to ensure the shell initializes correctly before running your script.

For most users, the simplest method involves invoking wt from PowerShell, Command Prompt, or even the Run dialog. The key is understanding that wt does not just open a window; it manages the lifecycle of the terminal instances. By passing arguments directly, you bypass the need to locate the correct profile in the settings menu every time.

Basic Syntax for Immediate Execution

To run a Bash command immediately upon startup, you should use the following structure in your command line:

wt --wsl bash -c "your_command_here"

This command tells Windows Terminal to open a new instance (or tab, depending on your default settings) targeting the WSL subsystem. The bash -c portion instructs the Bash interpreter to execute the string provided in quotes as a single command. This is crucial because it ensures the command runs in a non-interactive shell context, which is necessary for automation and immediate execution without waiting for user input.

If you have multiple WSL distributions installed, you may need to specify the exact distribution name instead of relying on the default. You can do this by replacing --wsl with --profile "Ubuntu-20.04", assuming that is the name defined in your settings.json. Always verify your profile names by checking the configuration file or running wt --list-profiles.

Handling Complex Commands and Arguments

When your Bash command includes spaces, special characters, or multiple commands chained together, proper quoting is essential. For example, if you want to navigate to a directory and list files, you might use:

wt --wsl bash -c "cd ~/projects && ls -la"

Note that the outer quotes define the argument passed to wt, while the inner logic is handled by Bash. If your command itself contains double quotes, you should escape them or use single quotes for the outer wrapper to prevent shell interpretation errors. For instance:

wt --wsl bash -c 'echo "Hello World"'

This technique allows for robust scripting where Windows Terminal acts merely as the container for your Linux environment. You can chain any valid Bash command, including Git operations, Python scripts, or system administration tasks. For more advanced scenarios involving Git Bash specifically, see How to Start Windows Terminal and Run Git Bash Command Immediately.

Customizing the Window Behavior

By default, wt opens a new window. However, you can modify this behavior using additional flags. To open the command in a new tab within an existing window, add the --new-tab flag:

wt --new-tab --wsl bash -c "npm start"

To split the pane horizontally or vertically, use --split horizontal or --split vertical. This is particularly useful for developers who want to keep their main workflow visible while running background processes or monitoring logs in a secondary pane. The command would look like this:

wt --split-vertical --wsl bash -c "tail -f /var/log/syslog"

These options provide flexibility in how the terminal session integrates with your current workspace. You can combine these flags to create complex layouts that suit your multitasking needs. Remember that if no window exists, wt will always launch a new one regardless of split flags, but subsequent calls will adhere to the specified layout rules.

Creating Persistent Shortcuts

For frequent use, consider creating a batch file or PowerShell alias to avoid typing long commands repeatedly. Create a file named run_bash.bat with the following content:

@echo off
wt --wsl bash -c "%*"

You can then call this script from anywhere in your system by simply typing run_bash echo hello. This abstracts away the complexity of the wt syntax and provides a clean interface for executing Linux commands from the Windows ecosystem. Alternatively, you can add an alias in your PowerShell profile for a more integrated experience.

If you are interested in opening the preview version of the terminal programmatically, check out Open Windows Terminal PREVIEW from command line for details on managing different versions of the application.

Frequently Asked Questions

Why does my command fail with a "command not found" error?

This usually happens because the WSL path is not included in the PATH variable when invoked via wt. Ensure you are calling the full path to the binary or sourcing your .bashrc file first. Adding source ~/.bashrc before your command often resolves environment variable issues.

Can I run this command without opening a new window?

No, Windows Terminal is designed to manage distinct sessions. Even if you use --new-tab, it requires an active terminal instance. There is no way to inject a command into an already open terminal window directly from the command line without using inter-process communication tools like conpty or third-party plugins.

Does this work with PowerShell Core inside Windows Terminal?

Yes, but you must change the profile target. Instead of --wsl, use --profile "PowerShell" and replace bash -c with powershell -Command. The syntax remains similar, but the shell interpreter changes to handle PowerShell-specific commands.

How do I pass arguments with spaces to the Bash command?

Enclose the entire command string in single quotes if it contains double quotes, or escape internal double quotes. For example: wt --wsl bash -c 'echo "file with spaces.txt"'. This prevents the outer shell from breaking the argument into separate parts.

Is there a performance penalty for launching wt frequently?

Launching wt is lightweight compared to starting a full GUI application, but it still incurs the overhead of initializing the WSL VM. For rapid-fire commands, consider keeping a persistent terminal window open and using Ctrl+Shift+C/V to copy-paste commands manually, or use a multiplexer like tmux inside WSL.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More