This is part three of my post series about Shellscripting, you can check out previous posts here:
Shellscripting: Introduction
Shellscripting: Co...
For further actions, you may consider blocking this person and/or reporting abuse
One veeeery useful and slightly weird thing to add here is that
$*
,"$*"
,$@
, and"$@"
all mean "all the arguments", but get expanded in different ways.Here's an example:
gives:
The quoted atpersand (
"$@"
) option is the only option that preserves argument groupings including spaces, while"$*"
treats all the arguments as one string, and$*
and$@
both expand to the fully split, ungrouped, unquoted arguments."$@"
behaves as if it were expanded with each element quoted separately, rather than"$*"
which behaves as if it were expanded and then the whole expansion quoted.(Note that this is the same as the behaviour for using arrays, in
"${array[*]}"
vs"${array[@]}"
.)I would agree on weird 😄but interesting nevertheless.
I didn't know about
$*
nor that quoting/unquoting can have such different results. Going to take note of this, thanks for sharing!Just to be picky about positionals, when you say
You kinda can, because you can use
shift
to reposition them,Each day you learn something new :D Thanks!
You might want to check out Shellcheck to avoid simple errors, probably unwanted behaviours, and deprecated code, and maybe even more. The online wiki is really helpful in explaining why things may go wrong, or why some code has been replaced.
Shellcheck is a great to add to a Git probject's .travis.yml (if you're using Travis.CI as a test-framework for commits, obvs.; otherwise call it from whatever else you're using to test uploaded code).
That's wrong!
Right version:
Whoops, missed that one, thanks for noticing!
I've been waiting for this post my whole life, thank you so much for sharing!
Hmmm.
function
s might be a better way than my current approach: just moving repeated instructions into a new shell script which I invoke when I need the "function" 😁