1
0
Fork 0
mirror of https://codeberg.org/Mo8it/How_To_Linux.git synced 2024-11-24 21:01:35 +00:00

Explain comments and read

This commit is contained in:
Mo 2022-09-26 20:27:53 +02:00
parent 2c435c1713
commit 08c686d8cf

View file

@ -192,9 +192,17 @@ We did define a temporary variable `USER` with the value `Tux`. This temporary v
You can use temporary variables not only to overwrite environment variables. These are basically variables that can be used by the program that you specify after their definition.
<!-- Comments -->
## Comments
<!-- TODO: read -->
In our first bash script, you can find three lines starting with a hashtag `#`. Two lines are comments, the shebang `#!` is an exception as a special comment at the beginning of a file that is not ignored while running the script. All other lines that start with `#` are comments that are ignored by the computer. Comments are only for humans to explain things.
Especially in long scripts, you should write comments to explain what the script and its "non trivial sections" do.
## User input
In a script, you can ask for user input. To do so, you can use the command `read`.
In our first bash script, we use `read` to take the answer of the user. The input is then saved in the variable `ANSWER`. You can choose a different name for this variable. After the line with `read`, you can use the variable storing the input as a normal variable.
<!-- TODO: if -->