简体   繁体   中英

Convert bash script to powershell

I need to convert what looks like a pretty simple bash script to powershell but I'm pretty new to both.

The original script is:

alias cptimestamp="date +"%Y%m%d%H%M" | clip"

I've gotten this far but I'm not sure:

function cptimestamp {
 cptimestamp="date +"%Y%m%d%H%M" | clip"
}

I'm having a hard time figuring out what the 'clip' part does.

The equivalent of date +"%Y%m%d%H%M" in PowerShell would be:

Get-Date -UFormat "%Y%m%d%H%M"

So your function should probably look like this:

function cptimestamp {
  Get-Date -UFormat "%Y%m%d%H%M" |Set-ClipBoard
}

If the purpose of your PowerShell function is to copy the current date and time to the Windows clipboard, I would probably use this:

function cptimestamp {
  [Windows.Forms.Clipboard]::SetText((Get-Date -Uformat "%Y%m%d%H%M"))
}

Or alternatively:

function cptimestamp {
  [Windows.Forms.Clipboard]::SetText((Get-Date -Format "yyyyMMddhhmmss"))
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM