I am trying to copy binary dependencies to other folder, so I use ldd
to see what should be copied.
However the script fails when copying. It "appears" '$'n'
characters when binary dependencies are copied.
Something is wrong, but I dont know what. Tried running command per command and cant see the fault.
What is the trouble here ?
Thanks
Script code
#!/usr/bin/env bash
set -e
chr=/home/myjail
cmds=( bash echo ls rm )
mkdir -p "$chr"/{bin,lib,lib64}
# copy commands
for app in "${cmds[@]}"; do
echo 'Added command:'"$app"
cp -v /bin/"$app" "$chr/bin"
done
# copy deps
for app in "${cmds[@]}";do
echo 'deps for:'"$app"
deps="$(ldd /bin/"$app" | egrep -o '/lib.*.[0-9]')"
for curdep in "${deps[@]}";do
echo "$curdep"
cp -v --parents "$curdep" "$chr"
done
done
Script output
furby@debian-haptic20:~# ./depcopy.sh
Added command:bash
'/bin/bash' -> '/var/lib/haproxy/bin/bash'
Added command:echo
'/bin/echo' -> '/var/lib/haproxy/bin/echo'
Added command:ls
'/bin/ls' -> '/var/lib/haproxy/bin/ls'
Added command:mysql
'/bin/mysql' -> '/var/lib/haproxy/bin/mysql'
deps for:bash
/lib/x86_64-linux-gnu/libtinfo.so.6
/lib/x86_64-linux-gnu/libdl.so.2
/lib/x86_64-linux-gnu/libc.so.6
/lib64/ld-linux-x86-64.so.2
cp: failed to get attributes of '/lib/x86_64-linux-gnu/libtinfo.so.6'$'n': No such file or directory
2
Answers
I’m using this script for this purpose:
copydep.sh
Run it like this:
Your
deps
variable should be an array, created withmapfile
and some redirection of process substitution:As you have it, it’s treated as a single string, which as you’ve seen, doesn’t work.