Skip to content

Instantly share code, notes, and snippets.

@markus2610
Created November 9, 2015 12:46
Show Gist options
  • Save markus2610/2a464e310a7b74f7cfd2 to your computer and use it in GitHub Desktop.
Save markus2610/2a464e310a7b74f7cfd2 to your computer and use it in GitHub Desktop.
Simple converter from batch (.bat) files to shell script (.sh)
#!/usr/bin/env bash
#
# Converts Windows batch script to Linux shell script
#
# Invocation:
# ./bat2sh script.bat
#
OUTFILE=${2:-${1%%.bat}.sh}
cat "$1" | \
sed \
-e 's/\bset\b/export/g' \
-e 's/%\([^/]\+\)%/${\1}/g' \
-e 's/^call.*$//g' \
-e 's/\r//' \
> "$OUTFILE"
chmod a+x "$OUTFILE"
@kippoguy69
Copy link

:3

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