[英]Convert bash script to powershell
我需要将看起来很简单的 bash 脚本转换为 powershell 但我对两者都很陌生。
原来的脚本是:
alias cptimestamp="date +"%Y%m%d%H%M" | clip"
我已经做到了这一点,但我不确定:
function cptimestamp {
cptimestamp="date +"%Y%m%d%H%M" | clip"
}
我很难弄清楚“剪辑”部分的作用。
PowerShell 中date +"%Y%m%d%H%M"
的等价物将是:
Get-Date -UFormat "%Y%m%d%H%M"
所以你的 function 应该看起来像这样:
function cptimestamp {
Get-Date -UFormat "%Y%m%d%H%M" |Set-ClipBoard
}
如果您的 PowerShell function 的目的是将当前日期和时间复制到 Windows 剪贴板,我可能会使用这个:
function cptimestamp {
[Windows.Forms.Clipboard]::SetText((Get-Date -Uformat "%Y%m%d%H%M"))
}
或者:
function cptimestamp {
[Windows.Forms.Clipboard]::SetText((Get-Date -Format "yyyyMMddhhmmss"))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.