Diogo
Diogo

Reputation: 733

Does powershell have something like "echo off" in command prompt mode?

In CMD command prompt, the echo off command disables the command prompt to be shown in the "Command Prompt Window".

i.e., it does not show the folder path anymore in the prompt, giving you a clean dark window.
I've put a gif below to make this very clear:

After the echo off command, the prompt doesn't show the path "C:\Users\TEMP>" anymore, until I type echo on again.

Does powershell have something like this? Sorry if this is silly. I tried to look for it, but didn't find a simple answer regarding the command prompt window (not a script execution).

enter image description here

Upvotes: 4

Views: 9366

Answers (3)

user2713404
user2713404

Reputation: 1

I use the following:
@echo on: Set-PSDebug -Trace 1
@echo off: Set-PSDebug -Trace 0

simple :)

Upvotes: -1

stackprotector
stackprotector

Reputation: 13588

The purpose of echo off is not to hide the prompt in cmd, but to disable command echoing (especially used in batch scripts). As PS does not have command echoing, it does not have a way to disable it. But as you just want to change your prompt:

You can change your prompt, but not to an empty string. If you return an empty string, PS will use its default prompt:

function prompt {}

Result:

PS>echo hello
hello
PS>

You could return a space character:

function prompt {' '}

Result:

 echo hello
hello

But then each line is prefixed with a space. You could also use the interesting hack from 7cc's answer and insert a character with an appended backspace character. But be aware that at least PowerShell 5.1 will currently crash, when using a prompt that is shorter than two characters. It will crash as soon as you type in { or for for example. And it will be buggy, if the prompt does not end with a space character (a character of the prompt disappears, when typing { or for for example). So it is probably the best to go with something like > followed by a space character as the shortest prompt:

function prompt {'> '}

The current built-in prompt is defined like this btw:

function prompt {
    $(if (Test-Path variable:/PSDebugContext) { '[DBG]: ' }
      else { '' }) + 'PS ' + $(Get-Location) +
        $(if ($NestedPromptLevel -ge 1) { '>>' }) + '> '
}

Read more about prompts in PS

Upvotes: 3

7cc
7cc

Reputation: 1179

Use the backspace control character.

function prompt { echo " `b" }

no prompt message

Upvotes: 3

Related Questions