enthuguy
asked on
how to pass arguments with spaces in shell script
Hi experts,
Could you help me with the problem. I'm trying to pass argument value with spaces from script1.sh to script2.sh
I'm using getopts
Script output
==========
[Ravee.Kumaravelu.NEC-AUMB S-25775] ¿ ./script1.sh -u scott -p tiger -h "192.22.22.22 192.22.22.33"
-u was triggered, Parameter: scott
-p was triggered, Parameter: tiger
-h was triggered, Parameter: 192.22.22.22 192.22.22.33
user is : scott
user pwd is : tiger
host server : 192.22.22.22 192.22.22.33
Invoking script2.sh with argument -u scott -p tiger -h "192.22.22.22 192.22.22.33"
Inside script2.sh
-u was triggered, Parameter: scott
-p was triggered, Parameter: tiger
-h was triggered, Parameter: 192.22.22.22
user is : scott
user pwd is : tiger
host server : 192.22.22.22
Attached the script for your quick reference.
Thanks in advance
script1.sh
script2.sh
Could you help me with the problem. I'm trying to pass argument value with spaces from script1.sh to script2.sh
I'm using getopts
Script output
==========
[Ravee.Kumaravelu.NEC-AUMB
-u was triggered, Parameter: scott
-p was triggered, Parameter: tiger
-h was triggered, Parameter: 192.22.22.22 192.22.22.33
user is : scott
user pwd is : tiger
host server : 192.22.22.22 192.22.22.33
Invoking script2.sh with argument -u scott -p tiger -h "192.22.22.22 192.22.22.33"
Inside script2.sh
-u was triggered, Parameter: scott
-p was triggered, Parameter: tiger
-h was triggered, Parameter: 192.22.22.22
user is : scott
user pwd is : tiger
host server : 192.22.22.22
Attached the script for your quick reference.
Thanks in advance
script1.sh
script2.sh
Change in script1.sh:
./script2.sh -u $user -p $pwd -h "$host"
Please note the double quotation marks around "$host"!
./script2.sh -u $user -p $pwd -h "$host"
Please note the double quotation marks around "$host"!
ASKER
thanks friends,
hi comfortjeanius, can you provide a link which as some sample
HI woolmilkporc, surrounding with quotes didnt help
hi comfortjeanius, can you provide a link which as some sample
HI woolmilkporc, surrounding with quotes didnt help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi woolmilkporc, my apologies, I updated the echo line and tested
working as expected. thanks very much!
working as expected. thanks very much!
http://stackoverflow.com/questions/13884554/passing-a-values-arguments-to-shell-script-with-spaces