Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day 20 - minor suggestions #2

Open
livialima opened this issue Mar 5, 2024 · 4 comments
Open

Day 20 - minor suggestions #2

livialima opened this issue Mar 5, 2024 · 4 comments
Assignees

Comments

@livialima
Copy link
Owner

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
Copy link
Contributor

matt-kita commented Apr 5, 2024

[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.

  • retain any text indentations
  • retain any metacharacters as e.g. $
  • etc...

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
Copy link
Owner Author

@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
Copy link
Contributor

matt-kita commented Jun 24, 2024

@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
Copy link
Owner Author

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

@livialima livialima transferred this issue from livialima/linuxupskillchallenge-oldfork Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants