add --bash option

This commit is contained in:
zawz 2021-06-22 10:52:28 +02:00
parent e5d0cf819d
commit ca2839ec9c
2 changed files with 14 additions and 4 deletions

View file

@ -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";

View file

@ -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"),