Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to pass arguments with spaces in shell script

Posted on 2013-06-21
5
Medium Priority
?
864 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 14

Expert Comment

by:comfortjeanius
ID: 39265698
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39265700
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
ID: 39265770
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 1400 total points
ID: 39265786
>> 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
ID: 39265835
Hi woolmilkporc, my apologies, I updated the echo line and tested

working as expected. thanks very much!
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses

650 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