Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The helloWorld function captures the first two arguments into local variables txt1 and txt2, then shifts them off, storing the remaining function arguments ($@) in the rest variable. It then echos the variable values, surrounded by single quotes:

...

Initially helloWorld arguments are:

  • $1My → stored in local variable txt1
  • $2name → stored in local variable txt2
  • $3is
  • $4Anna
  • $@ - My name is Anna

After shift; shift is called, helloWorld arguments are:

  • My previously now stored in local variable txt1
  • name previously now stored in local variable txt2
  • $1 - is
  • $2 - Anna
  • $@ - is Anna → stored in local variable rest

excercise 1

How would you call the helloWorld command to produce this output?

...

We;ve already touched on difference kinds of Quoting in the shell. But there is an additional subtlety when handling script arguments.

...