Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
added 8 characters in body
Source Link
ctrl-alt-delor
  • 28.8k
  • 11
  • 66
  • 113

It is the same as calling anything (a shell script, a C program, a python program, …) from a shell

If calling from any Unix shell, and the parameter has spaces, then you need to quote it.

sh my-shell-script hi "hello guys" bye

You can also use single quotes, these are more powerful. They stop the shell from interpreting anything ($, !, \, *, ", etc, except ')

sh my-shell-script hi 'hello guys' bye

You should also quote every variable useused within the function/script.

Note that in your example the arguments are falling apart before they get to the function (as they are passed to the script).

#!/bin/sh
my_procedure{
   echo "$1"
   echo "$2"
   echo "$3"
}
my_procedure("$@")

There is no way to do it automatically, in the script, as there is no way for the script to know which spaces are which (which words are together).

It is the same as calling anything (a shell script, a C program, a python program, …) from a shell

If calling from any Unix shell, and the parameter has spaces, then you need to quote it.

sh my-shell-script hi "hello guys" bye

You can also use single quotes, these are more powerful. They stop the shell from interpreting anything ($, !, \, *, ", etc, except ')

sh my-shell-script hi 'hello guys' bye

You should also quote every variable use within the function.

Note that in your example the arguments are falling apart before they get to the function (as they are passed to the script).

#!/bin/sh
my_procedure{
   echo "$1"
   echo "$2"
   echo "$3"
}
my_procedure("$@")

There is no way to do it automatically, in the script, as there is no way for the script to know which spaces are which (which words are together).

It is the same as calling anything (a shell script, a C program, a python program, …) from a shell

If calling from any Unix shell, and the parameter has spaces, then you need to quote it.

sh my-shell-script hi "hello guys" bye

You can also use single quotes, these are more powerful. They stop the shell from interpreting anything ($, !, \, *, ", etc, except ')

sh my-shell-script hi 'hello guys' bye

You should also quote every variable used within the function/script.

Note that in your example the arguments are falling apart before they get to the function (as they are passed to the script).

#!/bin/sh
my_procedure{
   echo "$1"
   echo "$2"
   echo "$3"
}
my_procedure("$@")

There is no way to do it automatically, in the script, as there is no way for the script to know which spaces are which (which words are together).

improve
Source Link
ctrl-alt-delor
  • 28.8k
  • 11
  • 66
  • 113

It is the same as calling anything (a shell script, a C program, a python program, …) from a shell

If calledcalling from any Unix shell, and the parameter has spaces, then you need to quote it.

sh my-shell-script hi "hello guys" bye

You can also use single quotes, these are more powerful. They stop the shell from interpreting anything ($, !, \, *, ", etc, except ')

sh my-shell-script hi 'hello guys' bye

You should also quote every variable use within the function.

Note that in your example the arguments are falling apart before they get to the function (as they are passed to the script).

#!/bin/sh
my_procedure{
   echo "$1"
   echo "$2"
   echo "$3"
}
my_procedure("$@")

There is no way to do it automatically, in the script, atas there is no way for the script to know which spaces are which (which words are together).

If called from any Unix shell, then you need to quote it.

sh shell hi "hello guys" bye

There is no way to do it in the script, at there is no way for the script to know which spaces are which (which words are together).

It is the same as calling anything (a shell script, a C program, a python program, …) from a shell

If calling from any Unix shell, and the parameter has spaces, then you need to quote it.

sh my-shell-script hi "hello guys" bye

You can also use single quotes, these are more powerful. They stop the shell from interpreting anything ($, !, \, *, ", etc, except ')

sh my-shell-script hi 'hello guys' bye

You should also quote every variable use within the function.

Note that in your example the arguments are falling apart before they get to the function (as they are passed to the script).

#!/bin/sh
my_procedure{
   echo "$1"
   echo "$2"
   echo "$3"
}
my_procedure("$@")

There is no way to do it automatically, in the script, as there is no way for the script to know which spaces are which (which words are together).

Source Link
ctrl-alt-delor
  • 28.8k
  • 11
  • 66
  • 113

If called from any Unix shell, then you need to quote it.

sh shell hi "hello guys" bye

There is no way to do it in the script, at there is no way for the script to know which spaces are which (which words are together).