3

I would like to build standalone bash binaries, which would hopefully work on a good portion of the linux distributions out there. Complete coverage is definitely not a goal. How would I approach this? Best-effort suggestions welcome. I understand that each distribution has e.g. unique readline implementations. If it is feasible, I would like to statically link a fixed version and ship it with the standalone bash on e.g. an usb stick.

Hope someone can help me with that :) cheers

3
  • 2
    So, which part are you having trouble with? Have you got bash to build yet? Are you having problems statically linking readline?
    – muru
    Aug 9 '19 at 11:01
  • Welcome to Unix Stackexchange! You can take the tour first and then learn how to ask a good question. This'll make it easier for us to help you.
    – andcoz
    Aug 9 '19 at 12:32
  • 1
    Just running the bash from centos on debian works for me -- no need to build anything ;-) bash come with its own readline, doesn't use the library from the system (just run ldd bash if you don't believe me). @muru building static binaries against glibc is only possible as long as they don't use any name resolution functions -- because glibc implements that by loading shared objects with dlopen. bash has to use name resolution for the /dev/tcp/host/port hack.
    – mosvy
    Aug 9 '19 at 14:36
3

Download the bash-static package from Debian and extract the executable.

ar p bash-static_*.deb data.tar.xz | tar -xJ ./bin/bash-static

If you want to see how it's done, look in the sources. The build instructions are in debian/rules. There's a lot of expansion going on, so run it:

debian/rules static-build

I think all you need is this (but I haven't tried):

./configure --enable-static-link
make

The question is why you'd want to do that. Virtually all distributions already have bash installed as /bin/bash, and it isn't optional. It would be more useful with zsh which in most distributions is available, but not installed by default. For zsh, you need (again, untried):

./configure --enable-ldflags=-static --disable-dynamic --disable-dynamic-nss
make
2
  • You may want to get the i386 one so it works on both x86 and x86_64. Aug 9 '19 at 22:13
  • For reference, Busybox doesn't ship with bash. I'm right now working on a setup where I need to use Busybox, but I have a bash script to run :(
    – Marcus
    Feb 10 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.