I want to use the official bash to run my unit tests but can't exec any local file in a script. Here is a minimal example what I want to do:
$ docker run -it bash
bash-4.4# cd /usr/local/bin/
bash-4.4# ./bashbug --version
GNU bashbug, version 4.4.19-release
bash-4.4# echo \#\!/usr/local/bin/bash \
> ./bashbug --version > script.sh
bash-4.4# chmod a+x script.sh
bash-4.4# ./script.sh
/usr/local/bin/bash: ./bashbug --version: No such file or directory
bash-4.4#
I one of the installed programs (/usr/local/bin/bashbug
) to illustrate the problem. As you can see, you can exec ./bashbug
directly, but not when it is executed by a bash script. How can I call it within script.sh
?
Edit
The example above has a bug. This is fixed by the accepted answer.
I found out that my original problem was a problem with link dependencies, which outputs:
./exec_test.sh: line 30: ./test: No such file or directory
When I call ldd
on test
I get:
ldd test
/lib64/ld-linux-x86-64.so.2 (0x7fe7ad476000)
libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7fe7ad476000)
libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7fe7ad476000)
libstdc++.so.6 => /path/bin/gcc-8.1.0/debug/libstdc++.so.6 (0x7fe7ac855000)
libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fe7ad476000)
libgcc_s.so.1 => /path/bin/gcc-8.1.0/debug/libgcc_s.so.1 (0x7fe7ac63d000)
libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fe7ad476000)
ld-linux-x86-64.so.2 => /path/bin/gcc-8.1.0/debug/ld-linux-x86-64.so.2 (0x7fe7ab49b000)
libboost_system.so.1.67.0 => /path/bin/gcc-8.1.0/debug/libboost_system.so.1.67.0 (0x7fe7ab291000)
Error relocating /path/bin/gcc-8.1.0/debug/libstdc++.so.6: __cxa_thread_atexit_impl: symbol not found
Error relocating /path/bin/gcc-8.1.0/debug/libgcc_s.so.1: __cpu_indicator_init: symbol not found
Error relocating /path/bin/gcc-8.1.0/debug/libgcc_s.so.1: __cpu_model: symbol not found
Probably a glibc
version issue.