Skip to main content
added 175 characters in body
Source Link
ilkkachu
  • 147.8k
  • 16
  • 268
  • 441

Positional parameters refer to the script's arguments in the main level of the script, but to function arguments in function body. So

print_something Something

would actually print Something.

If you want to pass scriptthe script's arguments to a function, you canmust do that explicitly:. Use

print_something "$1"

to pass the first argument, or

print_something "$@"

to pass all of them, though the function in example only uses the first one.

Positional parameters refer to function arguments in function body. So

print_something Something

would actually print Something

If you want to pass script arguments, you can do that explicitly:

print_something "$1"

or

print_something "$@"

to pass all of them.

Positional parameters refer to the script's arguments in the main level of the script, but to function arguments in function body. So

print_something Something

would actually print Something.

If you want to pass the script's arguments to a function, you must do that explicitly. Use

print_something "$1"

to pass the first argument, or

print_something "$@"

to pass all of them, though the function in example only uses the first one.

added 58 characters in body
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k

Positional parameters refer to function arguments in function body. So

print_something Something

would actually print Something

If you want to pass script arguments, you can do that explicitly:

print_something $1"$1"

or

print_something "$@"

to pass all of them.

Positional parameters refer to function arguments in function body. So

print_something Something

would actually print Something

If you want to pass script arguments, you can do that explicitly:

print_something $1

Positional parameters refer to function arguments in function body. So

print_something Something

would actually print Something

If you want to pass script arguments, you can do that explicitly:

print_something "$1"

or

print_something "$@"

to pass all of them.

Source Link
weirdan
  • 551
  • 4
  • 9

Positional parameters refer to function arguments in function body. So

print_something Something

would actually print Something

If you want to pass script arguments, you can do that explicitly:

print_something $1