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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With