Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 1
    To avoid variable name collisions, the safest way is to use the positional parameters. e.g., set -- "$(date +'%H')" ${1+"$@"}; <do whatever with $1>; shift; We never need worry about whether __hour pre-exists in the environment where we are to source stuff. Commented Apr 21, 2017 at 21:49
  • Also consider using the local builtin to keep variables within the scope of the function and its children without polluting the global environment. Commented Dec 17, 2021 at 18:12
  • Without -f, rm may prompt the user which we likely don't want here. rm -f -- "$file" would be more correct and would have also have the benefit of not returning an error if the file was already gone. Commented Mar 26, 2023 at 19:44
  • 1
    Note that in bash, unset may unset a function, if a variable by that name is not found. In that shell, it's a good habit to use unset -v var to make sure you unset a variable. Commented Mar 26, 2023 at 19:45