4

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

simlei
  • 51
  • 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 09 '19 at 11:01
  • Welcome to Unix Stackexchange! You can [take the tour](http://unix.stackexchange.com/tour) first and then learn [how to ask a good question](http://unix.stackexchange.com/help/how-to-ask). This'll make it easier for us to help you. – andcoz Aug 09 '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. –  Aug 09 '19 at 14:36

1 Answers1

4

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
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175