How to add subdir bin of first dir in GOPATH to PATH
echo $GOPATH
will print:
/mnt/star/program/go/package:/mnt/star/git_repository/workspace/go_workplace
There are 2 dir, I want to append the first dir's sub dir bin/
to $PATH
.
If I write $PATH=$PATH:$GOPATH/bin
, then actually it append 2 dir to $PATH
:
/mnt/star/program/go/package
This only contains dirs, it should be/mnt/star/program/go/package/bin
.
/mnt/star/git_repository/workspace/go_workplace/bin
This actually shouldn't be added to$PATH
.
BTW, there are cases that $GOPATH
only contains one dir, in that case simply append $GOPATH/bin
will work.
I am looking for a solution that fit for both cases. So, how to write this in bash config file?
linux bash shell
add a comment |
echo $GOPATH
will print:
/mnt/star/program/go/package:/mnt/star/git_repository/workspace/go_workplace
There are 2 dir, I want to append the first dir's sub dir bin/
to $PATH
.
If I write $PATH=$PATH:$GOPATH/bin
, then actually it append 2 dir to $PATH
:
/mnt/star/program/go/package
This only contains dirs, it should be/mnt/star/program/go/package/bin
.
/mnt/star/git_repository/workspace/go_workplace/bin
This actually shouldn't be added to$PATH
.
BTW, there are cases that $GOPATH
only contains one dir, in that case simply append $GOPATH/bin
will work.
I am looking for a solution that fit for both cases. So, how to write this in bash config file?
linux bash shell
add a comment |
echo $GOPATH
will print:
/mnt/star/program/go/package:/mnt/star/git_repository/workspace/go_workplace
There are 2 dir, I want to append the first dir's sub dir bin/
to $PATH
.
If I write $PATH=$PATH:$GOPATH/bin
, then actually it append 2 dir to $PATH
:
/mnt/star/program/go/package
This only contains dirs, it should be/mnt/star/program/go/package/bin
.
/mnt/star/git_repository/workspace/go_workplace/bin
This actually shouldn't be added to$PATH
.
BTW, there are cases that $GOPATH
only contains one dir, in that case simply append $GOPATH/bin
will work.
I am looking for a solution that fit for both cases. So, how to write this in bash config file?
linux bash shell
echo $GOPATH
will print:
/mnt/star/program/go/package:/mnt/star/git_repository/workspace/go_workplace
There are 2 dir, I want to append the first dir's sub dir bin/
to $PATH
.
If I write $PATH=$PATH:$GOPATH/bin
, then actually it append 2 dir to $PATH
:
/mnt/star/program/go/package
This only contains dirs, it should be/mnt/star/program/go/package/bin
.
/mnt/star/git_repository/workspace/go_workplace/bin
This actually shouldn't be added to$PATH
.
BTW, there are cases that $GOPATH
only contains one dir, in that case simply append $GOPATH/bin
will work.
I am looking for a solution that fit for both cases. So, how to write this in bash config file?
linux bash shell
linux bash shell
edited 1 hour ago
Eric Wang
asked 3 hours ago
Eric WangEric Wang
19119
19119
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can use:
PATH="$PATH:${GOPATH%%:*}/bin"
Or
PATH="$PATH:${GOPATH%:*}/bin"
Both will work because, there could be max 1 :
.
It will remove the part after :
. So in your first case it will remove second directory and in your second case, there will be no pattern like :*
, so there will be no change in the directory name.
Yes, that's exactly it! Only improvement this could get is default to~/go
if not defined (which is default since Go 1.8 I believe) but this answers the asked question perfectly, thanks!
– filbranden
2 hours ago
1
Works like a charm.
– Eric Wang
1 hour ago
add a comment |
PATH="$PATH:${GOPATH%%:*}/bin"
The asterisk is a glob, not a regular expression. Two percentage signs means to remove the maximum that it can match from the back, so even if there were three or more directories, you would only get the first one.
If there's nothing to remove, it doesn't remove anything, so you get the only path if there's only one.
It's the opposite... It's supposed to keep the first part, so you need to remove the last part. This is definitely the best answer, so if you fix it toPATH=$PATH:${GOPATH%%:*}/bin
I'll definitely upvote it!
– filbranden
2 hours ago
I read the question backwards. You're right, @filbranden. I'll fix it.
– Ken Jackson
2 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f500314%2fhow-to-add-subdir-bin-of-first-dir-in-gopath-to-path%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use:
PATH="$PATH:${GOPATH%%:*}/bin"
Or
PATH="$PATH:${GOPATH%:*}/bin"
Both will work because, there could be max 1 :
.
It will remove the part after :
. So in your first case it will remove second directory and in your second case, there will be no pattern like :*
, so there will be no change in the directory name.
Yes, that's exactly it! Only improvement this could get is default to~/go
if not defined (which is default since Go 1.8 I believe) but this answers the asked question perfectly, thanks!
– filbranden
2 hours ago
1
Works like a charm.
– Eric Wang
1 hour ago
add a comment |
You can use:
PATH="$PATH:${GOPATH%%:*}/bin"
Or
PATH="$PATH:${GOPATH%:*}/bin"
Both will work because, there could be max 1 :
.
It will remove the part after :
. So in your first case it will remove second directory and in your second case, there will be no pattern like :*
, so there will be no change in the directory name.
Yes, that's exactly it! Only improvement this could get is default to~/go
if not defined (which is default since Go 1.8 I believe) but this answers the asked question perfectly, thanks!
– filbranden
2 hours ago
1
Works like a charm.
– Eric Wang
1 hour ago
add a comment |
You can use:
PATH="$PATH:${GOPATH%%:*}/bin"
Or
PATH="$PATH:${GOPATH%:*}/bin"
Both will work because, there could be max 1 :
.
It will remove the part after :
. So in your first case it will remove second directory and in your second case, there will be no pattern like :*
, so there will be no change in the directory name.
You can use:
PATH="$PATH:${GOPATH%%:*}/bin"
Or
PATH="$PATH:${GOPATH%:*}/bin"
Both will work because, there could be max 1 :
.
It will remove the part after :
. So in your first case it will remove second directory and in your second case, there will be no pattern like :*
, so there will be no change in the directory name.
edited 2 hours ago
answered 2 hours ago
PRYPRY
2,15031025
2,15031025
Yes, that's exactly it! Only improvement this could get is default to~/go
if not defined (which is default since Go 1.8 I believe) but this answers the asked question perfectly, thanks!
– filbranden
2 hours ago
1
Works like a charm.
– Eric Wang
1 hour ago
add a comment |
Yes, that's exactly it! Only improvement this could get is default to~/go
if not defined (which is default since Go 1.8 I believe) but this answers the asked question perfectly, thanks!
– filbranden
2 hours ago
1
Works like a charm.
– Eric Wang
1 hour ago
Yes, that's exactly it! Only improvement this could get is default to
~/go
if not defined (which is default since Go 1.8 I believe) but this answers the asked question perfectly, thanks!– filbranden
2 hours ago
Yes, that's exactly it! Only improvement this could get is default to
~/go
if not defined (which is default since Go 1.8 I believe) but this answers the asked question perfectly, thanks!– filbranden
2 hours ago
1
1
Works like a charm.
– Eric Wang
1 hour ago
Works like a charm.
– Eric Wang
1 hour ago
add a comment |
PATH="$PATH:${GOPATH%%:*}/bin"
The asterisk is a glob, not a regular expression. Two percentage signs means to remove the maximum that it can match from the back, so even if there were three or more directories, you would only get the first one.
If there's nothing to remove, it doesn't remove anything, so you get the only path if there's only one.
It's the opposite... It's supposed to keep the first part, so you need to remove the last part. This is definitely the best answer, so if you fix it toPATH=$PATH:${GOPATH%%:*}/bin
I'll definitely upvote it!
– filbranden
2 hours ago
I read the question backwards. You're right, @filbranden. I'll fix it.
– Ken Jackson
2 hours ago
add a comment |
PATH="$PATH:${GOPATH%%:*}/bin"
The asterisk is a glob, not a regular expression. Two percentage signs means to remove the maximum that it can match from the back, so even if there were three or more directories, you would only get the first one.
If there's nothing to remove, it doesn't remove anything, so you get the only path if there's only one.
It's the opposite... It's supposed to keep the first part, so you need to remove the last part. This is definitely the best answer, so if you fix it toPATH=$PATH:${GOPATH%%:*}/bin
I'll definitely upvote it!
– filbranden
2 hours ago
I read the question backwards. You're right, @filbranden. I'll fix it.
– Ken Jackson
2 hours ago
add a comment |
PATH="$PATH:${GOPATH%%:*}/bin"
The asterisk is a glob, not a regular expression. Two percentage signs means to remove the maximum that it can match from the back, so even if there were three or more directories, you would only get the first one.
If there's nothing to remove, it doesn't remove anything, so you get the only path if there's only one.
PATH="$PATH:${GOPATH%%:*}/bin"
The asterisk is a glob, not a regular expression. Two percentage signs means to remove the maximum that it can match from the back, so even if there were three or more directories, you would only get the first one.
If there's nothing to remove, it doesn't remove anything, so you get the only path if there's only one.
edited 2 hours ago
answered 2 hours ago
Ken JacksonKen Jackson
1063
1063
It's the opposite... It's supposed to keep the first part, so you need to remove the last part. This is definitely the best answer, so if you fix it toPATH=$PATH:${GOPATH%%:*}/bin
I'll definitely upvote it!
– filbranden
2 hours ago
I read the question backwards. You're right, @filbranden. I'll fix it.
– Ken Jackson
2 hours ago
add a comment |
It's the opposite... It's supposed to keep the first part, so you need to remove the last part. This is definitely the best answer, so if you fix it toPATH=$PATH:${GOPATH%%:*}/bin
I'll definitely upvote it!
– filbranden
2 hours ago
I read the question backwards. You're right, @filbranden. I'll fix it.
– Ken Jackson
2 hours ago
It's the opposite... It's supposed to keep the first part, so you need to remove the last part. This is definitely the best answer, so if you fix it to
PATH=$PATH:${GOPATH%%:*}/bin
I'll definitely upvote it!– filbranden
2 hours ago
It's the opposite... It's supposed to keep the first part, so you need to remove the last part. This is definitely the best answer, so if you fix it to
PATH=$PATH:${GOPATH%%:*}/bin
I'll definitely upvote it!– filbranden
2 hours ago
I read the question backwards. You're right, @filbranden. I'll fix it.
– Ken Jackson
2 hours ago
I read the question backwards. You're right, @filbranden. I'll fix it.
– Ken Jackson
2 hours ago
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f500314%2fhow-to-add-subdir-bin-of-first-dir-in-gopath-to-path%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