0

Just editing a bash script and the last line is:

exec <&-

Hoping someone can explain. I'm guessing it has to do with the exit code of the previous command?

None
  • 1
  • 30
  • 155
  • 213

1 Answers1

0

exec <&- closes standard input (filedescriptor 0).

exec with just redirections but not other argument applies the redirections to the current process.

A redirection to or from &- means close. With numerical descriptors it doesn't matter if you do 0<&- or 0>&- — either version will close filedescriptor 0 (standard input). If you ommit the number > redirection means "use fildescriptor 1and<` means "use filedescriptor 0".

PSkocik
  • 55,062
  • 6
  • 86
  • 132
  • To make this answer more generally useful, could you add links to the relevant parts of https://www.gnu.org/software/bash/manual/bashref.html ? – ruakh May 07 '19 at 22:47
  • @ruakh I have since added an explanation. I'm not referencing the reference page, but it's info on the `&-` redirection is easy to find by `/` searching either `man sh` or `man bash` (the feature is POSIX compliant -- extensions like those of bash aren't needed for it to work). – PSkocik May 07 '19 at 22:53