Skip to content

Instantly share code, notes, and snippets.

@JimBobSquarePants
Last active May 2, 2019 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JimBobSquarePants/30757c2b7588d84cfb84750d24d4d6f0 to your computer and use it in GitHub Desktop.
Save JimBobSquarePants/30757c2b7588d84cfb84750d24d4d6f0 to your computer and use it in GitHub Desktop.
cmd to bash???
@echo Off
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '.\build.ps1'"
if not "%errorlevel%"=="0" goto failure
:success
ECHO successfully built project
REM exit 0
goto end
:failure
ECHO failed to build.
REM exit -1
goto end
:end
#!/bin/sh
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '.\build.ps1'"
if $errorlevel != "0" ;
then goto failure
fi
:success
echo successfully built project
# exit 0
goto end
:failure
echo failed to build.
# exit -1
goto end
:end
@shrayasr
Copy link

shrayasr commented May 2, 2019

A good place to start with checking shell scripts is Shell check. They help you catch all sorts of nasty possibilities before hand.

Its also worthwhile giving this a read. Talks about how to setup "strict mode" when writing shell scripts.

Also this looks more like a "transliteration" than a "translation" from the PS script. Which is a great place to start but not really idiomatic. Here's how I'd approach writing this (might also not be the best way)

#!/bin/bash

set -eu

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '.\build.ps1'"

if [ $# -ne 0 ]; then
  echo "Failed to build"
  exit 1
fi

echo "Successfully built project"
exit 0

Would be more than happy to help out more :)

Welcome to the beautiful (yet sometimes painful) world of shells scripts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment