Link to home
Start Free TrialLog in
Avatar of enthuguy
enthuguyFlag for Australia

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-AUMBS-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
Avatar of comfortjeanius
comfortjeanius
Flag of United States of America image

Change in script1.sh:

./script2.sh -u $user  -p $pwd -h "$host"

Please note the double quotation marks around "$host"!
Avatar of enthuguy

ASKER

thanks friends,

hi  comfortjeanius, can you provide a link which as some sample

HI woolmilkporc, surrounding with quotes didnt help
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi woolmilkporc, my apologies, I updated the echo line and tested

working as expected. thanks very much!