Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what the meaning of this link in linux script

Tags:

linux

bash

What is the meaning of the following which is on the top of linux script

#!/bin/bash
return &> /dev/null
like image 304
mailzyok Avatar asked Dec 12 '13 08:12

mailzyok


People also ask

What does link mean in Linux?

A symlink (also called a symbolic link) is a type of file in Linux that points to another file or a folder on your computer. Symlinks are similar to shortcuts in Windows. Some people call symlinks "soft links" – a type of link in Linux/UNIX systems – as opposed to "hard links."

What is link in Linux file?

In your Linux file system, a link is a connection between a file name and the actual data on the disk. There are two main types of links that can be created: "hard" links, and "soft" or symbolic links.

Why links are used in Linux?

Links are used in many instances: Sometimes to create a convenient path to a directory buried deep within the file hierarchy; other uses for links include: Linking libraries. Making sure files are in constant locations (without having to move the original) Keeping a “copy” of a single file in multiple locations.

How do I run a link in Linux?

Use the -s option to create a soft (symbolic) link. The -f option will force the command to overwrite a file that already exists. Source is the file or directory being linked to. Destination is the location to save the link – if this is left blank, the symlink is stored in the current working directory.


Video Answer


2 Answers

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.

like image 181
alvits Avatar answered Nov 09 '22 14:11

alvits


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.

like image 38
mvp Avatar answered Nov 09 '22 16:11

mvp