可以将此powershell脚本转换为bash脚本吗?动态bash命令?
param(
[string]$pod,
[string]$username,
[string]$pass,
[string]$environment,
[string]$delay,
[string]$utype,
[string]$etype,
[string]$url
)
$cmd = "protactor " + $f.name + " ";
if($pod -ne ""){
$cmd+=" --params.pod=$pod";
}
if($username -ne ""){
$cmd+=" --params.user=$username";
}
if($pass -ne ""){
$cmd+=" --params.pass=$pass"
}
if($utype -ne ""){
$cmd+=" --params.type=$utype"
}
if($url -ne ""){
$cmd+=" --params.url=$url"
}
if($etype -ne ""){
$cmd+=" --params.type=$etype"
}
$cmd
Invoke-Expression -Command:$cmd
有没有办法将上面的PowerShell脚本转换为bash脚本?非常感谢您,非常感谢
我做了这样的事情,但是我无法动态构建命令并在结尾进行调用,例如在Powershell中,我的问题是,如果没有通过论证,我可以动态地构建命令,我不'希望将其包含在命令中,例如,如果我不通过'-p xxx',那么我不想要' - params.pass = $ password'在bash的命令中显示。
#!/bin/bash
# how to use
# ./protactor-batch.sh -e xxx -u xxx -p xxx
while getopts u:p:e:s: flag
do
case "${flag}" in
u) username=${OPTARG};;
p) password=${OPTARG};;
e) pod=${OPTARG};;
s) sec=${OPTARG};;
esac
done
protractor $f --params.pod=$pod --params.user=$username --params.pass=$password
param(
[string]$pod,
[string]$username,
[string]$pass,
[string]$environment,
[string]$delay,
[string]$utype,
[string]$etype,
[string]$url
)
$cmd = "protactor " + $f.name + " ";
if($pod -ne ""){
$cmd+=" --params.pod=$pod";
}
if($username -ne ""){
$cmd+=" --params.user=$username";
}
if($pass -ne ""){
$cmd+=" --params.pass=$pass"
}
if($utype -ne ""){
$cmd+=" --params.type=$utype"
}
if($url -ne ""){
$cmd+=" --params.url=$url"
}
if($etype -ne ""){
$cmd+=" --params.type=$etype"
}
$cmd
Invoke-Expression -Command:$cmd
is there a way to convert above powershell script to bash script? thank you so much, much appreciated
I have done something like this but I am unable to build command dynamically and invoke it at the end like in powershell, my question is can I build a command dynamically if an argument is not passed, I don't want that to be included in the command, for example if I don't pass '-p xxx' then I don't want '--params.pass=$password' show up in the command in bash.
#!/bin/bash
# how to use
# ./protactor-batch.sh -e xxx -u xxx -p xxx
while getopts u:p:e:s: flag
do
case "${flag}" in
u) username=${OPTARG};;
p) password=${OPTARG};;
e) pod=${OPTARG};;
s) sec=${OPTARG};;
esac
done
protractor $f --params.pod=$pod --params.user=$username --params.pass=$password
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
``
``
`
`