2

I get an error when I try

 mkdir python && cd python && echo python > index.py

in my VS code terminal. This is the tutorial I am following. here

ErikMD
  • 13,377
  • 3
  • 35
  • 71

2 Answers2

5

could you please check your PowerShell version using the following command

$PSVersionTable.PSVersion

As far I know, one of the new features of Powershell 7.0 is Pipeline chain operators: && and || so this should work only on powershell 7

Ref: https://learn.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-70?view=powershell-7

Mahmoud Moawad
  • 697
  • 7
  • 14
1

Unfortunately I don't think we have such a thing as && chain operators in Windows PowerShell, would be nice though. This is pretty close to what you're looking for, it is a lot more verbose as you can see.

Note, mkdir is an alias for New-Item.

$folder = New-Item python -ItemType Directory
if($?){ Push-Location $folder; 'python' > index.py; Pop-Location }

Based on Mahmoud Moawad's answer, if you're running PowerShell Core:

New-Item python -ItemType Directory -Force 1>$null && Push-Location python && 'python' > index.py && Pop-Location
Santiago Squarzon
  • 41,465
  • 5
  • 14
  • 37