Reputation: 457
What is the meaning of the following which is on the top of linux script
#!/bin/bash
return &> /dev/null
Upvotes: 12
Views: 230
Reputation: 6758
The line is to protect users from sourcing the script.
When the script is run (not sourced but run), the script will proceed to the next lines until the end of file.
When the script is sourced, the script will just return and do nothing.
Upvotes: 15
Reputation: 13866
This discards the unwanted output of your program. Please check out this link, differences between >
, 2>
and &>
are very well explained over there.
Quoting:
command &>/dev/null
This syntax redirects both standard output and error output messages to /dev/null where it is ignored by the shell.
Upvotes: 0
Reputation: 116197
return
is supposed to return value from bash function.
When used exactly like in your example but without &> /dev/null
, it is invalid use because return
does not belong to body of bash function, and would print:
line 2: return: can only `return' from a function or sourced script
However, somebody decided to hide that error message by piping output to /dev/null
.
In other words, this all does not make much sense.
Upvotes: 5