livialima / linuxupskillchallenge

Learn the skills required to sysadmin a remote Linux server from the commandline.
https://linuxupskillchallenge.org/
Other
1.73k stars 226 forks source link

Day 20 - minor suggestions #52

Open livialima opened 6 months ago

livialima commented 6 months ago

Mod mail from u/linux26

Good tutorial! but a few things:

but in the first line and followed by a "!" The shebang doesn't just have to be in the first line, it has to be within the first two bytes. https://stackoverflow.com/a/3009280

Also consider using a here document instead of echo on multiple lines. cat << EOF

$() is better than `` since the latter gets really complicated to nest.

matt-kita commented 5 months ago

[First part of this comment was redacted after conducting more thorough tests]

Also consider using a here document instead of echo on multiple lines. cat << EOF

For a text spanning over more than 3 consecutive lines - yes, might be quite useful, but for any shorter texts - just a matter of personal preference, some might say "an overkill". Also note special use cases for "here docs" (read Here Documents section of man bash), where you need to e.g.

You may as well span multiple lines trailed with implicit \n characters within quotes for echo command (can use either single or double quotes - doesn't matter for this particular example, as we're not dealing with any parameter expansions), although it's actually not recommended.

$ cat echo_test.sh 
#!/usr/bin/env bash
echo "This is the first line for echo,
and this one is the second line.
This is the third and last one."
$ chmod +x echo_test.sh 
$ ./echo_test.sh 
This is the first line for echo,
and this one is the second line.
This is the third and last one.
$

$() is better than `` since the latter gets really complicated to nest.

Amen to that! :D

livialima commented 3 months ago

@matt-kita would you like to incorporate this detail into the Day 20 lesson? Any other suggestions to the lesson flow are appreciated. Let me know if you want this issue assigned to you.

matt-kita commented 3 months ago

@matt-kita would you like to incorporate this detail into the Day 20 lesson? Any other suggestions to the lesson flow are appreciated. Let me know if you want this issue assigned to you.

By "this detail", did you mean applying and explaining the proper use of "here documents" instead of multiple echo commands, or improving the command substitution syntax with $( ), or both? :) I can do both (along with some additional, minor script tuning). Sure, you can assign it to me ;)

livialima commented 3 months ago

@matt-kita specially the use of $( ) but both is good, if you're willing. Thanks for the help!