comando de salida de Unix equivalente en PowerShell?
Frecuentes
Visto 1,003 veces
3
I'm converting unix scripts into powersshell scripts. while converting i came across the line "exit $rc" in unix script.
I want to know the powershell equivalent for Unix exit command.
Ayúdame en este sentido.
Gracias por adelantado
2 Respuestas
5
Hay un exit [<code>]
keyword in PowerShell. If you use exit
in a script, it doesn't matter what scope you are in and even what nesting level, the script will exit. If you execute exit
in the PowerShell console it will exit the PowerShell session. You can use the automatic variable $LastExitCode
to see the value returned by exit.
respondido 27 nov., 13:07
3
Don't forget that PowerShell also has exceptions. It might be more appropriate to throw an exception when you encounter an error. That depends on the particulars of the scripts you are porting of course, but it's another tool in the toolbox you can use.
respondido 27 nov., 13:08
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas unix powershell or haz tu propia pregunta.
In unix code a=10, b=20, [$a -eq $b], rc=$?, exit $rc; What is the equivalent code in powershell for above code? - Raj
@user2990846 Please do not move the target. If you have an additional question: post an additional question. However, SO is not a free translation service, so you'll eventually need to read a tutorial to get accustomed to the language, which is quite similar to bash in some ways, but fundamentally different in others. - Ansgar Wiechers