1

protoc depends on higer version of libstdc++. Usually on bash shell we writes:

LD_PRELOAD=/root/.conda/envs/myfish/lib/libstdc++.so.6.0.26 thirdparty/protobuf/bin/protoc

I try to use fish shell to do the same thing.

⋊> /h/m/rank4 on master ⨯ set LD_PRELOAD /root/.conda/envs/myfish/lib/libstdc++.so.6.0.26 thirdparty/protobuf/bin/protoc                                                                                                  (base) 15:02:02
⋊> /h/m/rank4 on master ⨯ echo $LD_PRELOAD                                                                                                                                                                                (base) 15:02:10
/root/.conda/envs/myfish/lib/libstdc++.so.6.0.26 thirdparty/protobuf/bin/protoc

However, fish shell doesnot recongize the space between word libstdc++.so.6.0.26 and word thirdparty.
The expect behavior is that script uses LD_PRELOAD library and executes command protoc.
What's the right writing?

mariolu
  • 624
  • 8
  • 17

1 Answers1

3

Just use the same code:

LD_PRELOAD=/root/.conda/envs/myfish/lib/libstdc++.so.6.0.26 thirdparty/protobuf/bin/protoc

Since fish 3.1, that'll just work.


set LD_PRELOAD /root/.conda/envs/myfish/lib/libstdc++.so.6.0.26 thirdparty/protobuf/bin/protoc

Sets the variable "LD_PRELOAD" to the values "/root/.conda/envs/myfish/lib/libstdc++.so.6.0.26" and "thirdparty/protobuf/bin/protoc"

It doesn't recognize "thirdparty/protobuf/bin/protoc" as a command, just as another argument to the set command and hence another value for the variable.

If you do need to use a separate set (like in fish < 3.1), you need to first set the variable, and then run the command. In addition, you need to "export" the variable so that the command you run actually receives a copy. So the code is:

set -x LD_PRELOAD /root/.conda/envs/myfish/lib/libstdc++.so.6.0.26
thirdparty/protobuf/bin/protoc
# and now erase $LD_PRELOAD again:
set -e LD_PRELOAD

or, alternatively, open a new block make a local $LD_PRELOAD so it is erased automatically at the end:

begin
    # the "-l" makes the variable local,
    # the "-x" passes it to external commands
    set -lx LD_PRELOAD /root/.conda/envs/myfish/lib/libstdc++.so.6.0.26
    thirdparty/protobuf/bin/protoc
end
faho
  • 14,470
  • 2
  • 37
  • 47
  • 1
    "Since fish 3.1, that'll just work" -- alternately use the `env` command for the same purpose: `env VAR=value VAR2=value2 /some/command` – glenn jackman Apr 20 '21 at 15:04