Is there a way to reduce the size of a shell script?
Asked by
Marquetry
I'm looking for a tool that can help me "compile" a shell script into a more compact file that can still be executed by a regular shell interpreter. Ideally, I want to reduce the size by removing all indentation, deleting comments, renaming variables and functions to shorter names, and possibly using aliases for commonly used code snippets. So far, I haven't found anything beyond basic compression tools like .zip.
Answers
What you're really after is a minifier instead of a standard compressor. Check out this GitHub resource: https://github.com/Zuzzuc/Bash-minifier. It should do what you need for minimizing your shell script.
Reply to this answer
Why do you need to compress your script so much? The difference in size is usually pretty negligible, even a couple of KB doesn't make a huge impact on most systems.
Reply to this answer
You could try to convert your script to Rust and compile it. That might help with size and performance. Plus, asking a language model can point you in the right direction for that.
Z5_muxSel: That's an interesting idea! Rust's performance could definitely help if you're trying to optimize for size.
Reply to this answer
Reply to this answer
Iโm not great at coding, but when I'm done with my script, I just delete it using `rm -rf script`. It's the ultimate compression!
Reply to this answer
Add your answer
Answers are reviewed before publication.
!CueTheMusic: Minifying makes sense! I hadn't thought of that term. Thanks for the tip!