1

When I do something in my script like

rlwrap -f words.txt LD_PRELOAD=mylib.so command "$@" 

I always get something like

rlwrap: error: cannot execute LD_PRELOAD=mylib.so no such file or directory 

Even though that file totally exists and removing rlwrap would work just fine.

How do I put LD_PRELOAD in rlwrap? basically I want to make mylib.so apply to my 'command' only.

I did try putting LD_PRELOAD=mylib.so in from of rlwrap, it runs, but LD_PRELOAD didn't apply to command as I wished.

CuriousMind
  • 15,168
  • 20
  • 82
  • 120
  • Looks to me like `rlwrap` is taking `LD_PRELOAD=mylib.so` as the command. Have you tried `LD_PRELOAD=mylib.so rlwrap -f words.txt command "$@" ` – Mort May 01 '16 at 18:17
  • @Mort yes, but that didn;t work. Then LD_PRELOAD was not passed into command – CuriousMind May 01 '16 at 18:52
  • Hmmm. On my system, `LD_PRELOAD=/lib/libc.so.6 rlwrap sh -c 'echo $LD_PRELOAD'` prints `/lib/libc.so.6`. If it does the same on your system, `rlwrap` _is_ passing `LD_PRELOAD` into the environment of the rlwrapped command – Hans Lub May 01 '16 at 22:08
  • @HansLub Yes, but the linker links `mylib.so` against `rlwrap` which is not desired – hek2mgl May 02 '16 at 05:12
  • @hek2mgl: That depends. If `mylib.so` defines just a few symbols that aren't used by `rlwrap` (which is a common case) it is quite OK to do it this way. – Hans Lub May 02 '16 at 07:07
  • If that's *really* the case then yes. But that's an edge case. Wrapping the command in a shell like I showed looks cleaner imo – hek2mgl May 02 '16 at 08:12
  • As I said, that depends. But yes, your solution will _always_ work, and mine _may_ go wrong. – Hans Lub May 02 '16 at 09:44

1 Answers1

0

You can wrap the command in a shell:

rlwrap -f words.txt bash -c 'LD_PRELOAD=mylib.so command "$@"' - "$@"
hek2mgl
  • 152,036
  • 28
  • 249
  • 266