Open livialima opened 8 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
@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 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 ;)
@matt-kita specially the use of $( )
but both is good, if you're willing. Thanks for the help!
Mod mail from u/linux26