Skip to main content
Post Closed as "Duplicate" by Gilles 'SO- stop being evil' shell-script
fixed grammar
Source Link
Nidal
  • 9.1k
  • 11
  • 59
  • 74

I'm trying to pass multiple argument to a function, but one of them is consist of two words and I want shell function to deal with it as one arg:

args=("$@") function(){ echo ${args[0]} echo ${args[1]} echo ${args[2]} } 

when iI call this command `sh shell hi hello guys byesh shell hi hello guys bye

I get this

hi hello guys 

butBut what I really want is:

hi hello guys bye 

I'm trying to pass multiple argument to a function, but one of them is consist of two words and I want shell function to deal with it as one arg:

args=("$@") function(){ echo ${args[0]} echo ${args[1]} echo ${args[2]} } 

when i call this command `sh shell hi hello guys bye

I get this

hi hello guys 

but what I really want is

hi hello guys bye 

I'm trying to pass multiple argument to a function, but one of them is consist of two words and I want shell function to deal with it as one arg:

args=("$@") function(){ echo ${args[0]} echo ${args[1]} echo ${args[2]} } 

when I call this command sh shell hi hello guys bye

I get this

hi hello guys 

But what I really want is:

hi hello guys bye 
Source Link
user78050
  • 1.1k
  • 3
  • 11
  • 16

How to pass argument with spaces to a shell script function?

I'm trying to pass multiple argument to a function, but one of them is consist of two words and I want shell function to deal with it as one arg:

args=("$@") function(){ echo ${args[0]} echo ${args[1]} echo ${args[2]} } 

when i call this command `sh shell hi hello guys bye

I get this

hi hello guys 

but what I really want is

hi hello guys bye