Chris
Chris

Reputation: 1019

difference in 0>&- and 0<&- I/O redirections

In example below 0>&- works that ssh-keygen command exists when input prompt appears. Shouldn't it be 0<&- (close stdin) instead? Both 0>&- and 0<&- seem to be working in the same way (when ssh-keygen's input/confirmation prompt appears it's closed) - how to explain it?

user@system:~/.ssh$ ls -al test123
ls: cannot access 'test123': No such file or directory
user@system:~/.ssh$ ssh-keygen -b 2048 -t rsa -f test123 -q -N "" 0>&-
user@system:~/.ssh$
user@system:~/.ssh$ ls -al test123
-rw------- 1 user user 1823 Sep 21 08:01 test123
user@system:~/.ssh$ ssh-keygen -b 2048 -t rsa -f test123 -q -N "" 0>&-
test123 already exists.
Overwrite (y/n)? user@system:~/.ssh$
user@system:~/.ssh$
user@system:~/.ssh$ ssh-keygen -b 2048 -t rsa -f test123 -q -N "" 0<&-
test123 already exists.
Overwrite (y/n)? user@system:~/.ssh$

In a documentation there is:

n<&-

    Close input file descriptor n.
0<&-, <&-

    Close stdin.
n>&-

    Close output file descriptor n.

Upvotes: 1

Views: 38

Answers (1)

noah
noah

Reputation: 2776

There is no difference between 0>&- and 0<&-.

There is a difference between >&- and <&-.

That difference is:

>&- defaults to n=1

<&- defaults to n=0

See more at this StackExchange post

Upvotes: 1

Related Questions