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
Solved

how to pass arguments with spaces in shell script

Posted on 2013-06-21
5
848 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
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 350 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wifi not working on Raspberry Pi 3? 2 81
capture pcap with filtered traffic 1 85
maybe no no httpd.conf 6 62
RHEL 6.7 Gnome Desktop on VMware 6 VM 9 68
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

829 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