INTRODUCTION
bash2cpp converts simple bash scripts to c++ code.
It requires c++17 for file IO and expects c++ code to run in Linux.
Code also uses boost::format for printf format specifier conversion.
Though, with some effort Linux dependency can be removed but this is not
in radar at this moment.
Reasons why you may want to try bash2cpp are:
- Faster execution time by using native binary as opposed to shell script.
- Code obfiscuation to prevent modification.
bash2cpp is not a complete translator but does a good job for simple scripts.


REQUIREMENTS
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
INSTALLATION
USAGE
- mkdir -p gen
- node app.js test.sh gen/test.cpp
- optional (beautify code)
- astyle -q -n gen/%test.cpp
- if you have WSL
- wsl g++ gen/test.cpp -o gen/test -lpcre -std=c++17 -g
- if you are on linux
- g++ gen/test.cpp -o gen/test -lpcre -std=c++17 -g
- Size and speed optimization
- g++ gen/test.cpp -o gen/test -lpcre -std=c++17 -O3 -ffunction-sections -fdata-sections -Wl,--gc-sections -flto -g
IMPROVEMENT
BUILD TESTS
TROUBLESHOOTING
If something doesn't work, simplify your shell script and convert one at a time.
Review missing functionality list.
MISSING FUNCTIONALITY
HIGH PRIORITY
- echo -e missing
- checkroot.sh: while loop read from #9 file descriptor
- checkroot.sh: exec descriptor handling
- handle :exit 0
- exec 0>&1
- variable.sh: dropping TIMESTAMP variables
- functions: parameter expansion inside awk string does not work
- if [[ ( $username == "admin" && $password == "secret" ) ]] does not work
- if [ -z ${VAR+x} ];
- dmesg -s 131072 > gen/dmesg doesn't work
- echo {A..Z}{0..9} does not work
- echo 1.{1..9}
- str+=", " doesn't work
- doesn't handle special characters well
- has problems with cat << EOF .. EOF
- regex string match in substring.sh does not work
LOW PRIORITY
- supports only 11 arguments
- partial read support
- echo -n is assumed to be the first three characters