S
S
Sergey2018-07-27 21:29:48
linux
Sergey, 2018-07-27 21:29:48

What does it do in bash?

Hello, please tell me what these lines do in bash:

d=$(dirname $0)

if [ -f "/etc/license" ]; then
echo "The panel is already installed."
exit
fi

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
xotkot, 2018-07-28
@t3g1ng

d=$(dirname $0)
$0 here is a variable that indicates the path to the file of the running script from the place where this script was launched from.
The variable d will be assigned (=) the path to the directory of the script being run, here dirname will cut off the ending.
You can surprise it by adding variable output

echo "0 = $0"
echo "d = $d"

to see the full path to the directory of the script being run, and not just from the launch location, you can do this:
DIR=$(dirname $(readlink -e "$0"))
echo "DIR = $DIR"

about the second part:
if [ -f "/etc/license" ]; then
echo "The panel is already installed."
exit
fi

the condition (if ... then ... fi) is checked for the existence of a file (-f) along the path "/etc/license", if it exists, it will output (echo) the message (The panel is already installed.) to the console and exit ( exit) from the program.

A
AVKor, 2018-07-27
@AVKor

google://bash dirname etc.

G
gremlintv2, 2018-07-27
@gremlintv2

-f file - True if file exists and is a regular file.
So yes, -f means file (./$NAME.tar in your case) exists and is a regular file (not a device file or a directory for example).
If the "/etc/license" file exists and does not represent a device or folder
Print "The panel is already installed."

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question