Solved

how to pass arguments with spaces in shell script

Posted on 2013-06-21
5
703 Views
Last Modified: 2013-06-21
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
0
Comment
Question by:enthuguy
  • 2
  • 2
5 Comments
 
LVL 14

Expert Comment

by:comfortjeanius
Comment Utility
0
 
LVL 68

Expert Comment

by:woolmilkporc
Comment Utility
Change in script1.sh:

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

Please note the double quotation marks around "$host"!
0
 

Author Comment

by:enthuguy
Comment Utility
thanks friends,

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

HI woolmilkporc, surrounding with quotes didnt help
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 350 total points
Comment Utility
>> HI woolmilkporc, surrounding with quotes didnt help <<

Here is the output I'm getting by running your scripts with the mentioned modification:

# ./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 192.22.22.33
user is : scott
user pwd is : tiger
host server : 192.22.22.22 192.22.22.33

What else did you expect?
0
 

Author Closing Comment

by:enthuguy
Comment Utility
Hi woolmilkporc, my apologies, I updated the echo line and tested

working as expected. thanks very much!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now