From ca2839ec9c1b3d297f182b18fc38b93d7be28653 Mon Sep 17 00:00:00 2001 From: zawz Date: Tue, 22 Jun 2021 10:52:28 +0200 Subject: [PATCH] add --bash option --- src/main.cpp | 17 +++++++++++++---- src/options.cpp | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 289f4fa..060c1ba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -94,9 +94,17 @@ int main(int argc, char* argv[]) { first_run=false; // resolve shebang - binshebang = basename(shebang); - shebang_is_bin = ( basename(argv[0]) == binshebang ); - parse_bash = (options["debashify"] || binshebang == "bash" || binshebang == "lxsh"); + if(options["bash"]) + { + parse_bash=true; + shebang = "#!/usr/bin/env bash"; + } + else + { + binshebang = basename(shebang); + shebang_is_bin = ( basename(argv[0]) == binshebang ); + parse_bash = (options["debashify"] || binshebang == "bash" || binshebang == "lxsh"); + } // detect if need execution if(options['e']) @@ -129,7 +137,6 @@ int main(int argc, char* argv[]) ctx.data=filecontents.data(); - ctx = make_context(filecontents, file, parse_bash); if(is_exec) { @@ -140,6 +147,8 @@ int main(int argc, char* argv[]) { auto pp = parse_text(ctx); tsh = pp.first; + if(options["bash"]) + tsh->shebang = "#!/usr/bin/env bash"; ctx = pp.second; if(shebang_is_bin) // resolve lxsh shebang to sh tsh->shebang="#!/bin/sh"; diff --git a/src/options.cpp b/src/options.cpp index 443af50..c8d00b7 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -32,6 +32,7 @@ ztd::option_set options( { ztd::option('I', "no-include", false, "Don't resolve %include commands"), ztd::option('R', "no-resolve", false, "Don't resolve %resolve commands"), ztd::option("no-extend", false, "Don't add lxsh extension functions"), + ztd::option("bash", false, "Force bash parsing"), ztd::option("debashify", false, "Attempt to turn a bash-specific script into a POSIX shell script"), ztd::option("remove-unused", false, "Remove unused functions and variables"), ztd::option("list-cmd", false, "List all commands invoked in the script"),