Skip to content

Instantly share code, notes, and snippets.

@janmalec
Forked from markus2610/bat2sh.sh
Last active January 5, 2023 09:45
Show Gist options
  • Save janmalec/118463af534e17796a2ae69c4638a48a to your computer and use it in GitHub Desktop.
Save janmalec/118463af534e17796a2ae69c4638a48a 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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment