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

06-script: user-defined variables in scripts #512

Open
stouffer opened this issue Feb 10, 2017 · 2 comments
Open

06-script: user-defined variables in scripts #512

stouffer opened this issue Feb 10, 2017 · 2 comments
Assignees
Labels
type:clarification Suggest change to make lesson clearer type:enhancement Propose enhancement to the lesson

Comments

@stouffer
Copy link

In order to remind learners about the idea of shell variables (which are introduced in 05-loops) and reinforce good practice, legibility, helping future users, etc., I'd like to suggest that we add another example after introducing comments. Specifically, it could look like:

$ nano middle.sh
# Select lines from the middle of a file.
# Usage: bash middle.sh filename end_line num_lines
filename="$1"
end_line="$2"
num_lines="$3"
head -n "$end_line" "$filename" | tail -n "$num_lines"

Since variables are already come up in the previous lesson, I expect that the added time should be quite minimal whereas the payoff is quite important since some learners might forget that they can define their own variables or, worse, think that they are constrained to use the default special variables.

The downside is that many instructors are already pressed for time at this stage without new/additional material. Therefore, ways to cut back that don't strike me personally as too large a sacrifice could include:

  1. Removing the "Why Isn't It Doing Anything?" section. I find that this is often quite confusing for learners and in my experience isn't that common an error when starting to write one's own scripts.
  2. Moving the "Why Isn't It Doing Anything?" section to be a new challenge along the lines of the "Debugging Scripts" challenge that already exists.
@deppen8
Copy link
Contributor

deppen8 commented Sep 8, 2021

Closing as part of old issue cleanup. If there is still appetite for this change, we can reopen for further discussion.

@deppen8 deppen8 closed this as completed Sep 8, 2021
fmichonneau pushed a commit to fmichonneau/shell-novice that referenced this issue Sep 9, 2021
@gcapes
Copy link
Contributor

gcapes commented Sep 9, 2021

I really like this idea. It makes the script much more legible, which is an important take-home in itself, and the variable names have already been inferred in the comment.

@gcapes gcapes reopened this Sep 9, 2021
@gcapes gcapes added type:clarification Suggest change to make lesson clearer type:enhancement Propose enhancement to the lesson labels Sep 9, 2021
@gcapes gcapes self-assigned this Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:clarification Suggest change to make lesson clearer type:enhancement Propose enhancement to the lesson
Projects
None yet
Development

No branches or pull requests

3 participants