mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 03:54:04 +08:00
20243132fb
This tries to open the given file to use as stdin, and if it fails,
for any reason, it uses /dev/null instead.
This is useful in cases where we would otherwise do either of these:
```fish
test -r /path/to/file
and string match foo < /path/to/file
cat /path/to/file 2>/dev/null | string match foo
```
This both makes it nicer and shorter, *and* helps with TOCTTOU - what if the file is removed/changed after the check?
The reason for reading /dev/null instead of a closed fd is that a closed fd will often cause an error.
In case opening /dev/null fails, it still skips the command.
That's really a last resort for when the operating system
has turned out to be a platypus and not a unix.
Fixes #4865
(cherry picked from commit
|
||
---|---|---|
.. | ||
cmds | ||
python_docs_theme | ||
commands.rst | ||
completions.rst | ||
conf.py | ||
contributing.rst | ||
design.rst | ||
faq.rst | ||
fish_for_bash_users.rst | ||
fish_indent_lexer.py | ||
fish_synopsis.py | ||
index.rst | ||
interactive.rst | ||
language.rst | ||
license.rst | ||
prompt.rst | ||
relnotes.rst | ||
tutorial.rst |