copied to clipboard!
string shell

[Shell] Run and understand Generate a prompt when logging in to a terminal

created-2026/01/05 updated-2026/03/24

Introduction

This repository uses several commands to generate the prompt that appears when you log in to the terminal.

The commands you need to install

  1. None in paticular

Quickstart

Run the command to display the host name, current directory, and account name.

ubuntu

echo "prompt=""$(echo $(hostname))""@""$(echo $(hostname))"":""$(pwd | sed "s/\/home\/$(whoami)/~/")""$"
Output results
prompt=hostname:currenctDirectory accountName$

macos

MacPorts

echo "prompt=""$(echo $(hostname) | cut -d . -f1)"":""$(basename "$(pwd)" | sed "s/$(whoami)/~/")" "$(whoami)""$"
Output results
prompt=hostname@hostname:currenctDirectory$

windows

WSL2

echo "prompt=""$(whoami)""@""$(echo $(hostname))"":""$(pwd | sed "s/\/home\/$(whoami)/~/")""$"
Output results
prompt=accountName@hostname:currenctDirectoryPath$

MSYS2 MINGW64

echo "prompt=""$(whoami)""@""$(echo $(hostname))"" ""$(echo $MSYSTEM)"" ""$(pwd | sed 's/\/home\/user/~/')"
Output results
prompt=accountName@hostname MSYSTEMName currenctDirectoryPath

Procedure

ubuntu

Click to open details

Advance confirmation

Enter the following command into the terminal and if command not found does not appear, it is OK.

Nothing in paticular

preinstall

Please install the command that shows “command not found” in the terminal using the following command.

Nothing in paticular

command

Executing the following command in the terminal should output a string similar to the following:

echo "prompt=""$(echo $(hostname))""@""$(echo $(hostname))"":""$(pwd | sed "s/\/home\/$(whoami)/~/")""$"
Detail
prompt=hostname@hostname:currenctDirectory$

macos

Click to open details

Advance confirmation

Enter the following command into the terminal and if command not found does not appear, it is OK.

Nothing in paticular

Enter the following command into the terminal and if command not found does not appear, it is OK….

preinstall

If the command not found appears in the terminal, install it using the following command and set an alias.

Nothing in paticular

command

Executing the following command in the terminal should output a string similar to the following:

echo "prompt=""$(echo $(hostname) | cut -d . -f1)"":""$(basename "$(pwd)" | sed "s/$(whoami)/~/")" "$(whoami)""$"
Detail
prompt=hostname:currenctDirectory accountName$

windows

Click to open details

Advance confirmation

Enter the following command into the prompt and if command not found does not appear, it’s OK.

WSL2
Nothing in paticular
MSYS2 MINGW64
Nothing in paticular

*Windows has been confirmed to work with WSL2 and MSYS2 MINGW64. Please install WSL2 if possible, and if you are unable to set it up, you can run it by installing MSYS2, but there may be some commands that can only be run in WSL2. Please refer to the following article for instructions on how to install WSL2 and MSYS2.

preinstall

If the command not found appears in the prompt, please install it using the following command.

WSL2
Nothing in paticular
MSYS2 MINGW64
Nothing in paticular

command

By executing the following command at the prompt, you should get the following output:

WSL2
echo "prompt=""$(whoami)""@""$(echo $(hostname))"":""$(pwd | sed "s/\/home\/$(whoami)/~/")""$"
Detail
prompt=accountName@hostname:currenctDirectoryPath$
MSYS2 MINGW64
echo "prompt=""$(whoami)""@""$(echo $(hostname))"" ""$(echo $MSYSTEM)"" ""$(pwd | sed 's/\/home\/user/~/')"
Detail
prompt=accountName@hostname MSYSTEMName currenctDirectoryPath

Afterword

It may be easier to understand if you break it down into four commands:

echo $(hostname) | cut -d . -f1
basename "$(pwd)"
whoami
echo "$"

Leave a Reply

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

©︎ 2025-2026 todo