Need to identify executable files via boolean shell test construct
1
vote
2
answers
108
views
I am trying to symlink executable files to a
bin
directory within a docker script. I need a way to identify executables and return boolean status. I've been trying this:
-sh
for i in ../src/u-boot/tools/*; do if ! [[ "readelf -h $i | grep -q DYN" ]]; then ln -s $i .; fi; done
It doesn't work and I do not understand why.
If I look at the actual return values I see the values I expect:
-shellsession
root@0f1bca692c90:/home/work/bin# readelf -h ../src/u-boot/tools/mkimage |grep -q DYN
root@0f1bca692c90:/home/work/bin# echo $?
0
root@0f1bca692c90:/home/work/bin# readelf -h ../src/u-boot/tools/mkimage.c |grep -q DYN
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
root@0f1bca692c90:/home/work/bin# echo $?
1
I'm assuming that I misunderstand how Bash interprets return values. I've tried with single and double brackets, and I get the same behavior.
**Update**
I was able to get it working like this:
-sh
RUN for i in ../src/u-boot/tools/*; do if /usr/bin/readelf -h $i | grep -q DYN; then ln -s $i .; fi; done
Asked by mreff555
(131 rep)
Oct 24, 2024, 02:21 PM
Last activity: Oct 27, 2024, 11:16 AM
Last activity: Oct 27, 2024, 11:16 AM