In bash, how do I expand a wildcard while it's inside double quotes?
I would like to write the following function in bash:
go() {
cd "~/project/entry ${1}*"
}
What this would do is to cd into a project subdirectory with prefix entry
(note space) and possibly a long suffix. I would only need to give it a partial name and it will complete the suffix of the directory name.
So, if for example, I have the following folders:
~/project/entry alpha some longer folder name
~/project/entry beta another folder name
~/project/entry gamma
I can run go b
and it will put me into ~/project/entry beta another folder name
.
The problem is, of course, that the wildcard doesn't expand inside double quotes. I cannot omit the quotes because then I will not be able to capture the spaces properly.
How do I get the wildcard to expand while at the same time preserving the spaces?
bash wildcard space
add a comment |
I would like to write the following function in bash:
go() {
cd "~/project/entry ${1}*"
}
What this would do is to cd into a project subdirectory with prefix entry
(note space) and possibly a long suffix. I would only need to give it a partial name and it will complete the suffix of the directory name.
So, if for example, I have the following folders:
~/project/entry alpha some longer folder name
~/project/entry beta another folder name
~/project/entry gamma
I can run go b
and it will put me into ~/project/entry beta another folder name
.
The problem is, of course, that the wildcard doesn't expand inside double quotes. I cannot omit the quotes because then I will not be able to capture the spaces properly.
How do I get the wildcard to expand while at the same time preserving the spaces?
bash wildcard space
1
Quoting rules are applied character-by-character -- there's no reason for an entire word to be quoted the same way. One can, for instance,'do something'"like $this"'to mix quoting styles'
.
– Charles Duffy
Feb 17 '15 at 16:52
See also When to wrap quotes around a shell variable?
– tripleee
Jul 13 at 12:20
add a comment |
I would like to write the following function in bash:
go() {
cd "~/project/entry ${1}*"
}
What this would do is to cd into a project subdirectory with prefix entry
(note space) and possibly a long suffix. I would only need to give it a partial name and it will complete the suffix of the directory name.
So, if for example, I have the following folders:
~/project/entry alpha some longer folder name
~/project/entry beta another folder name
~/project/entry gamma
I can run go b
and it will put me into ~/project/entry beta another folder name
.
The problem is, of course, that the wildcard doesn't expand inside double quotes. I cannot omit the quotes because then I will not be able to capture the spaces properly.
How do I get the wildcard to expand while at the same time preserving the spaces?
bash wildcard space
I would like to write the following function in bash:
go() {
cd "~/project/entry ${1}*"
}
What this would do is to cd into a project subdirectory with prefix entry
(note space) and possibly a long suffix. I would only need to give it a partial name and it will complete the suffix of the directory name.
So, if for example, I have the following folders:
~/project/entry alpha some longer folder name
~/project/entry beta another folder name
~/project/entry gamma
I can run go b
and it will put me into ~/project/entry beta another folder name
.
The problem is, of course, that the wildcard doesn't expand inside double quotes. I cannot omit the quotes because then I will not be able to capture the spaces properly.
How do I get the wildcard to expand while at the same time preserving the spaces?
bash wildcard space
bash wildcard space
asked Feb 17 '15 at 16:49
Ana
5,06853474
5,06853474
1
Quoting rules are applied character-by-character -- there's no reason for an entire word to be quoted the same way. One can, for instance,'do something'"like $this"'to mix quoting styles'
.
– Charles Duffy
Feb 17 '15 at 16:52
See also When to wrap quotes around a shell variable?
– tripleee
Jul 13 at 12:20
add a comment |
1
Quoting rules are applied character-by-character -- there's no reason for an entire word to be quoted the same way. One can, for instance,'do something'"like $this"'to mix quoting styles'
.
– Charles Duffy
Feb 17 '15 at 16:52
See also When to wrap quotes around a shell variable?
– tripleee
Jul 13 at 12:20
1
1
Quoting rules are applied character-by-character -- there's no reason for an entire word to be quoted the same way. One can, for instance,
'do something'"like $this"'to mix quoting styles'
.– Charles Duffy
Feb 17 '15 at 16:52
Quoting rules are applied character-by-character -- there's no reason for an entire word to be quoted the same way. One can, for instance,
'do something'"like $this"'to mix quoting styles'
.– Charles Duffy
Feb 17 '15 at 16:52
See also When to wrap quotes around a shell variable?
– tripleee
Jul 13 at 12:20
See also When to wrap quotes around a shell variable?
– tripleee
Jul 13 at 12:20
add a comment |
1 Answer
1
active
oldest
votes
Move the quotes. Just don't quote the *
. Probably also good not to quote the ~
.
go() {
cd ~/"project/entry ${1}"*
}
That being said if this matches more than one thing cd
will use the first match and ignore all the other matches.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f28566599%2fin-bash-how-do-i-expand-a-wildcard-while-its-inside-double-quotes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Move the quotes. Just don't quote the *
. Probably also good not to quote the ~
.
go() {
cd ~/"project/entry ${1}"*
}
That being said if this matches more than one thing cd
will use the first match and ignore all the other matches.
add a comment |
Move the quotes. Just don't quote the *
. Probably also good not to quote the ~
.
go() {
cd ~/"project/entry ${1}"*
}
That being said if this matches more than one thing cd
will use the first match and ignore all the other matches.
add a comment |
Move the quotes. Just don't quote the *
. Probably also good not to quote the ~
.
go() {
cd ~/"project/entry ${1}"*
}
That being said if this matches more than one thing cd
will use the first match and ignore all the other matches.
Move the quotes. Just don't quote the *
. Probably also good not to quote the ~
.
go() {
cd ~/"project/entry ${1}"*
}
That being said if this matches more than one thing cd
will use the first match and ignore all the other matches.
edited Feb 17 '15 at 17:25
answered Feb 17 '15 at 16:51
Etan Reisner
57.7k44785
57.7k44785
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f28566599%2fin-bash-how-do-i-expand-a-wildcard-while-its-inside-double-quotes%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
1
Quoting rules are applied character-by-character -- there's no reason for an entire word to be quoted the same way. One can, for instance,
'do something'"like $this"'to mix quoting styles'
.– Charles Duffy
Feb 17 '15 at 16:52
See also When to wrap quotes around a shell variable?
– tripleee
Jul 13 at 12:20