[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Official bash minifier
From: |
Koichi Murase |
Subject: |
Re: Official bash minifier |
Date: |
Mon, 8 Feb 2021 19:06:51 +0800 |
2021年2月8日(月) 1:02 Chet Ramey <chet.ramey@case.edu>:
> If you want to see what bash can do for you, run it with the
> `--pretty-print' option on a shell script.
Chet, thank you for pointing out `--pretty-print'! I haven't
recognized that option.
2021年2月8日(月) 6:47 Peng Yu <pengyu.ut@gmail.com>:
> This seems to be a good start. But it is still far from a true
> minifier, as variable names are not shortened, which is a key feature
> of a minifier.
Peng, I think it is almost impossible to safely change the variable
names and function names in shell scripts because of its language
nature. In shell scripts, variables and functions can be dynamically
specified by their name, which means that the variable and function
names can actually carry important meanings in the shell programs.
Also, shell languages use dynamic scoping by default so that the
callee can see the variable defined in the callers, which means that
even if a variable is defined locally using the `local' builtin,
actually the variable can be accessed by an arbitrary place.
Minifiers are quite popular in, e.g., JavaScript. But, there are
reasons: It uses lexical scoping as in most languages. Also, a local
variable cannot be accessed by its name. (By the way, global variables
can be accessed through their name in JavaScript, so the global name
won't be changed by minifiers). So, all the access points of local
variables can be statically analyzed in JavaScript. This is the reason
that the variable and function names can be changed in JavaScript.
By the way, what is your reason for looking for Bash-script minifiers?
In the JavaScript case, I can understand the purpose to reduce the
traffic for many big libraries. But for the Bash script, first, there
are no big libraries, and the size of scripts currently used is
limited. Also, I don't know the use case to transfer so many Bash
scripts in a situation that a quick response is required. Do you
actually want obfuscators but not minifiers?
--
Koichi