Skip to content

Feature Request: pwsh -x flag #9463

@krystian-wojtas

Description

@krystian-wojtas

Posix shell

Posix shells have very helpful -x cli flag. It could be also enabled inside script code with line 'set -x'. It shows commands as they are exactly executed

Example shell code

% cat hello.sh
#!/bin/sh

set -x

msg="world"
echo "hello $msg"

Output

% ./hello.sh
+ msg=world
+ echo hello world
hello world

If there is something unexpected in script, then I can easily copy interesting line to another terminal and run it.

Powershell

My best finding is 'Set-PSDebug -Trace 2' function.

Example powershell code

% cat hello.ps
#!/usr/bin/pwsh

Set-PSDebug -Trace 2;

$msg="world"
write-host "hello $msg"

Output

% ./hello.ps
DEBUG:    5+  >>>> $msg="world"

DEBUG:     ! SET $msg = 'world'.
DEBUG:    6+  >>>> write-host "hello $msg"

hello world

Powershell shows lines of source code. It does not evaluate variables values. I would like to see write-host "hello world" as extra debug message.

Question

Is it possible to see executed lines of script code in powershell? Could it evaluate variables values before printing debug message about executing command? How to do it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions