Skip to content

<? operator (and >? consistency) #4865

@drwilly

Description

@drwilly

As you might know some modern programming languages support a ?. operator.
The ?. operator works just like the well-known . but has a built-in null-check, so myobj?.someMethod() is equivalent to if(myobj != null) myobj.someMethod()
In fish I've recently come across the pattern test -r file; and cmd < file which is very similar to the above example with the null-check replaced by a file-readability-test. My idea was to express this pattern simply as cmd <? file: If file is not readable, the command is skipped.

Interestingly the <? operator is already implemented in fish, however it's current behaviour is to fail if the file exists. As for as I can see for the stdin redirect this doesn't make any sense whatsoever.

Now that brings me to the consistency topic:
Currently, >? file fails noisily if file exists, while <? would skip quietly if file does not exist.
Would you consider changing the bahaviour of >? or rather suggest a different operator for <??
RFC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions