Fish-shell: Extra file descriptors does not work in $XDG_CONFIG_HOME/fish/config.fish

Created on 25 Jul 2019  路  1Comment  路  Source: fish-shell/fish-shell

I found that extra file descriptors does not work in the $XDG_CONFIG_HOME/fish/config.fish:

For example, using this test command, sh -c 'echo test >&3' 3>| cat. It would work in fish after fish completes startup, but if I put the same command in $XDG_CONFIG_HOME/fish/config.fish, I get a Bad file descriptor.

Please see the following console output for a detailed repro:

ntkme@penguin ~> fish --version
fish, version 3.0.2
ntkme@penguin ~> : 1. Create a new config dir
ntkme@penguin ~> mkdir -p $HOME/xdg_config_test/fish
ntkme@penguin ~> touch $HOME/xdg_config_test/fish/config.fish
ntkme@penguin ~> cat $HOME/xdg_config_test/fish/config.fish
ntkme@penguin ~> : 2. Start fish with empty config
ntkme@penguin ~> env XDG_CONFIG_HOME=$HOME/xdg_config_test fish
ntkme@penguin ~> : 3. Now run our test command
ntkme@penguin ~> sh -c 'echo test >&3' 3>| cat
test
ntkme@penguin ~> : 4. Quit this shell
ntkme@penguin ~> exit
ntkme@penguin ~> : 5. Now put the test command into config.fish
ntkme@penguin ~> echo "sh -c 'echo test >&3' 3>| cat" > $HOME/xdg_config_test/fish/config.fish
ntkme@penguin ~> cat $HOME/xdg_config_test/fish/config.fish
sh -c 'echo test >&3' 3>| cat
ntkme@penguin ~> : 6. Start fish with test command in config.fish
ntkme@penguin ~> env XDG_CONFIG_HOME=$HOME/xdg_config_test fish
sh: 1: 3: Bad file descriptor
ntkme@penguin ~>

More interestingly, I actually found a syntax that can workaround it. If I wrap the test command as:

begin                                                                                                                              
   [command that uses additional file descriptor]
end | cat

For example:

ntkme@penguin ~> cat $HOME/xdg_config_test/fish/config.fish
begin
  sh -c 'echo test >&3' 3>| cat
end | cat
ntkme@penguin ~> env XDG_CONFIG_HOME=$HOME/xdg_config_test fish
test
ntkme@penguin ~> 
bug

Most helpful comment

I can reproduce, the good news is that it's fixed in master.

>All comments

I can reproduce, the good news is that it's fixed in master.

Was this page helpful?
0 / 5 - 0 ratings