LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-28-2014, 07:04 AM   #1
theEditor876
LQ Newbie
 
Registered: Jun 2014
Posts: 4

Rep: Reputation: Disabled
Passing arguments with SPACES to bash script


Hey guys!

Lets say i have a shell script looking like this:

Code:
#!/bin/bash
var1="wehavea spacehere"
var2="11.02.2013"

./dosomething.sh $var1 $var2
dosomething.sh:

Code:
#!/bin/bash

whatever=123

./someprogram $1 $2 $whatever
when i pass $var1 and $var2 to dosomething.sh, $var1 will get split up in 2 arguments!
calling dosomething.sh like this:

Code:
./dosomething.sh "$var1" "$var2"

does not work, either.

Can somebody tell me how to properly pass arguments with a space in between them?
Thank you!
 
Old 06-28-2014, 08:30 AM   #2
mark_alfred
Senior Member
 
Registered: Jul 2003
Location: Toronto, Ontario, Canada
Distribution: Ubuntu Linux 16.04, Debian 9
Posts: 1,327

Rep: Reputation: 154Reputation: 154
I'm not sure, but perhaps a backward slash would work.

Code:
#!/bin/bash
var1="wehavea\ spacehere"
var2="11.02.2013"

./dosomething.sh $var1 $var2
 
Old 06-28-2014, 08:41 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,620

Rep: Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577
Quote:
Originally Posted by theEditor876 View Post
dosomething.sh:

Code:
#!/bin/bash

whatever=123

./someprogram $1 $2 $whatever
when i pass $var1 and $var2 to dosomething.sh, $var1 will get split up in 2 arguments!
calling dosomething.sh like this:

Code:
./dosomething.sh "$var1" "$var2"

does not work, either.

Can somebody tell me how to properly pass arguments with a space in between them?
You are passing the argument correctly there, but dosomething.sh isn't using it correctly. You need to quote the arguments there, too:
Code:
./someprogram "$1" "$2" $whatever
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Passing arguments with blanks to du in a bash shell script impert Programming 13 06-12-2014 05:57 AM
Bash Script passing arguments dimitriauxio Linux - Newbie 8 09-16-2013 10:19 AM
[SOLVED] Bash script passing file names with spaces into another program yilez Programming 10 04-04-2013 06:45 AM
[SOLVED] BASH - passing arguments Garrett85 Programming 4 01-09-2013 04:03 PM
[SOLVED] passing commands as arguments to functions in bash script mastahyeti Linux - General 3 05-31-2010 07:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration