Space separated argument to script
up vote
0
down vote
favorite
I'm trying to use a wrapper bash script to execute some command with one parameter separated by space 'A B'.
foo-wrapper.sh content:
#/!bin/bash
foo $1
When running foo-wrapper.sh:
$bash -x foo-wrapper.sh "'A B'"
+ Error: foo ''''A' 'B''''
The expected call would be: foo 'A B'
Any ideas how to make that work?
bash
add a comment |
up vote
0
down vote
favorite
I'm trying to use a wrapper bash script to execute some command with one parameter separated by space 'A B'.
foo-wrapper.sh content:
#/!bin/bash
foo $1
When running foo-wrapper.sh:
$bash -x foo-wrapper.sh "'A B'"
+ Error: foo ''''A' 'B''''
The expected call would be: foo 'A B'
Any ideas how to make that work?
bash
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to use a wrapper bash script to execute some command with one parameter separated by space 'A B'.
foo-wrapper.sh content:
#/!bin/bash
foo $1
When running foo-wrapper.sh:
$bash -x foo-wrapper.sh "'A B'"
+ Error: foo ''''A' 'B''''
The expected call would be: foo 'A B'
Any ideas how to make that work?
bash
I'm trying to use a wrapper bash script to execute some command with one parameter separated by space 'A B'.
foo-wrapper.sh content:
#/!bin/bash
foo $1
When running foo-wrapper.sh:
$bash -x foo-wrapper.sh "'A B'"
+ Error: foo ''''A' 'B''''
The expected call would be: foo 'A B'
Any ideas how to make that work?
bash
bash
edited 2 days ago
Micha Wiedenmann
9,6891164102
9,6891164102
asked 2 days ago
ntrax111
406
406
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
In the wrapper replace
$1
by"$1"
.
If your arguments/variables contain space characters, you need to quote them to prevent them from being split.In the call instead of
"'A B'"
use one of"A B"
,'A B'
orA B
.
These are the most usual ways of specifying strings in BASH. (Note that the whitespace only makes a difference in the 3rd case. You would have to use quotes in the first two cases no matter whether you have a space or not.)
If you want to play around a little to get a feeling, you can start with:
$ foo() { echo "count: $#"; echo "arg 1: $1"; echo "arg 2: $2"; }
$ foo A B C
count: 2
arg 1: A B
arg 2: C
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
In the wrapper replace
$1
by"$1"
.
If your arguments/variables contain space characters, you need to quote them to prevent them from being split.In the call instead of
"'A B'"
use one of"A B"
,'A B'
orA B
.
These are the most usual ways of specifying strings in BASH. (Note that the whitespace only makes a difference in the 3rd case. You would have to use quotes in the first two cases no matter whether you have a space or not.)
If you want to play around a little to get a feeling, you can start with:
$ foo() { echo "count: $#"; echo "arg 1: $1"; echo "arg 2: $2"; }
$ foo A B C
count: 2
arg 1: A B
arg 2: C
add a comment |
up vote
1
down vote
accepted
In the wrapper replace
$1
by"$1"
.
If your arguments/variables contain space characters, you need to quote them to prevent them from being split.In the call instead of
"'A B'"
use one of"A B"
,'A B'
orA B
.
These are the most usual ways of specifying strings in BASH. (Note that the whitespace only makes a difference in the 3rd case. You would have to use quotes in the first two cases no matter whether you have a space or not.)
If you want to play around a little to get a feeling, you can start with:
$ foo() { echo "count: $#"; echo "arg 1: $1"; echo "arg 2: $2"; }
$ foo A B C
count: 2
arg 1: A B
arg 2: C
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
In the wrapper replace
$1
by"$1"
.
If your arguments/variables contain space characters, you need to quote them to prevent them from being split.In the call instead of
"'A B'"
use one of"A B"
,'A B'
orA B
.
These are the most usual ways of specifying strings in BASH. (Note that the whitespace only makes a difference in the 3rd case. You would have to use quotes in the first two cases no matter whether you have a space or not.)
If you want to play around a little to get a feeling, you can start with:
$ foo() { echo "count: $#"; echo "arg 1: $1"; echo "arg 2: $2"; }
$ foo A B C
count: 2
arg 1: A B
arg 2: C
In the wrapper replace
$1
by"$1"
.
If your arguments/variables contain space characters, you need to quote them to prevent them from being split.In the call instead of
"'A B'"
use one of"A B"
,'A B'
orA B
.
These are the most usual ways of specifying strings in BASH. (Note that the whitespace only makes a difference in the 3rd case. You would have to use quotes in the first two cases no matter whether you have a space or not.)
If you want to play around a little to get a feeling, you can start with:
$ foo() { echo "count: $#"; echo "arg 1: $1"; echo "arg 2: $2"; }
$ foo A B C
count: 2
arg 1: A B
arg 2: C
edited 2 days ago
answered 2 days ago
Micha Wiedenmann
9,6891164102
9,6891164102
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372828%2fspace-separated-argument-to-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown