linux - 无法在 bash 脚本中正确设置环境变量 LD_PRELOAD

标签 linux bash

我想编写一个脚本来执行以下命令:

${CROSS_COMPILE}gcc -static myinit.c -o myinit
cd initramfs
fakeroot # this is pure magic (it allows us to pretend to be root)
mkdir -p dev
mknod dev/console c 5 1
chown root init
find . | cpio -H newc -o > ../initramfs.cpio # <-- this is the actual initramfs
exit # leave the fakeroot shell
cd ..

截至目前,我每天必须手动执行此操作 200 次。所以我想它可以转换成一个 scipt 来自动化这个过程。按照这个论坛中的其他答案,我尝试的是:

更新代码

    #!/bin/bash

 LD_PRELOAD="/usr/lib64/libfakeroot/libfakeroot-tcp.so" printenv "LD_PRELOAD" libfakeroot-tcp.so

 printenv "LD_PRELOAD"

     printenv "LD_PRELOAD"


    arm-xilinx-linux-gnueabi-gcc -static echotest.c -o init
        cp init initramfs
        cd initramfs
        fakeroot
        mkdir -p dev
        mknod dev/console c 5 1
        chown root init
        find . | cpio -H newc -o > ../initramfs.cpio
        exit
        cd ..

我将其保存在 test.sh 中,并使该文件可执行。这是我得到的输出:

更新输出

/usr/lib64/libfakeroot/libfakeroot-tcp.so
libfakeroot-tcp.so
ERROR: ld.so: object 'libfakeroot-tcp.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object 'libfakeroot-tcp.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object 'libfakeroot-tcp.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object 'libfakeroot-tcp.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object 'libfakeroot-tcp.so' from LD_PRELOAD cannot be preloaded: ignored.
fakeroot: FAKEROOTKEY set to 39730
fakeroot: nested operation not yet supported
1289 blocks

我得到了预期的文件 initramfs.cpio ,但为什么会出现这些错误?

最佳答案

当你说

LD_PRELOAD="/usr/lib64/libfakeroot/libfakeroot-tcp.so" printenv "LD_PRELOAD" libfakeroot-tcp.so

在 printenv 命令期间设置 LD_PRELOAD 变量。尝试:

export LD_PRELOAD="/usr/lib64/libfakeroot/libfakeroot-tcp.so"

arm-xilinx-linux-gnueabi-gcc -static echotest.c -o init
...

关于linux - 无法在 bash 脚本中正确设置环境变量 LD_PRELOAD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24096290/

相关文章:

linux - 存储库 'http://dl.google.com/linux/chrome/deb stable Release' 未签名

mysql - Bash 函数返回似乎无法正常工作

bash - 使用 Bash 逐行读取并保留空间

linux - 使用 locate、pipe 和 grep 查找名称中包含特定关键字的文件

linux - 如何将这些带有 tar pigz 命令的管道转换为 ssh 远程执行?

linux - 让 R 在库目录中查找文件

linux - Bash 中的局部变量与 Perl 中的一样吗?

bash - 字符串的符号错误号

linux - 如何在 Bash 中将空格分隔的文本转换为行

python - Python CLI 脚本中的管道和提示