Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: confusing behavior with ~ in path #4140

Closed
gopherbot opened this issue Sep 23, 2012 · 16 comments
Closed

cmd/go: confusing behavior with ~ in path #4140

gopherbot opened this issue Sep 23, 2012 · 16 comments
Milestone

Comments

@gopherbot
Copy link

by stefantalpalaru:

GOPATH="~/go:~/go_mine" should work by expanding the tilde to the user's home
directory just like the PATH variable it mimics does on POSIX systems.
@rsc
Copy link
Contributor

rsc commented Sep 23, 2012

Comment 1:

GOPATH will not do ~ expansion.
Your claim that "POSIX systems" do this is false. Only bash does this,
and we can't possibly keep up with all the magic that bash does. If
you have an Ubuntu system, try dash or ksh or pdksh and you'll see
that ~ expansion within the variable is quite uncommon.

Status changed to Unfortunate.

@gopherbot
Copy link
Author

@rsc
Copy link
Contributor

rsc commented Sep 23, 2012

Comment 3:

The link describes tilde expansion as a property of the shell input syntax.
Instead of writing
    GOPATH="~/go:~/go_mine"
you should write
    GOPATH=~/go:~/go_mine
and then the shell will expand the ~ when creating the environment
variable. This already works, because it doesn't have anything to do
with the go command.
What you asked for in this issue is to be able to write the quoted
version, creating an environment variable that itself contains ~, and
force every program that looks at the environment variable to apply
the tilde expansion itself. That is not required by POSIX, and it is
not done by any shell I could find, except bash, which does
everything.
Russ

@gopherbot
Copy link
Author

Comment 4 by stefantalpalaru:

Dropping the quotes is good enough for me. Can we get an example and a note about tilde
expansion not working inside the quotes on this page: http://golang.org/doc/code.html ?

@rsc
Copy link
Contributor

rsc commented Sep 23, 2012

Comment 5:

I don't believe the page should or needs to say anything about tilde
expansion not working inside quotes, especially given that it does not
use either one in the examples. I'm sorry you ran into trouble, but
tilde expansion pretty much never works inside quotes. This is a fact
of Unix, not of Go. (Bash's $PATH interpretation is the anomaly here.)

@alexbrainman
Copy link
Member

Comment 6:

What about windows. Do not forget about windows :-)
Alex

@rsc
Copy link
Contributor

rsc commented Sep 24, 2012

Comment 7:

Thanks Alex. All the more reason not to give ~ special meaning. Just
don't write the quotes, and it will work for all the tools you are
using, Go and otherwise, and all the environment variables you need to
set. The rule is simple: if you quote ~ it doesn't get expanded.

@gopherbot
Copy link
Author

Comment 8 by dan.carley:

Is it possible to at least surface this error more clearly?
As a newcomer using `go get` to try out gotour - it appears that Go fails to create the
directory structure in GOPATH, but the first and only sign of this is when hg (in this
case) tries to clone a repo into the expanded path:
dan@dan-MBP ~/projects/personal $ mkdir golang
dan@dan-MBP ~/projects/personal $ export GOPATH="~/projects/personal/golang"
dan@dan-MBP ~/projects/personal $ go get -v -x code.google.com/p/go-tour/gotour
code.google.com/p/go-tour (download)
cd .
hg clone -U https://code.google.com/p/go-tour
~/projects/personal/golang/src/code.google.com/p/go-tour
# cd .; hg clone -U https://code.google.com/p/go-tour
~/projects/personal/golang/src/code.google.com/p/go-tour
abort: No such file or directory:
/home/dan/projects/personal/golang/src/code.google.com/p/go-tour/.hg
package code.google.com/p/go-tour/gotour: exit status 255

@rsc
Copy link
Contributor

rsc commented Nov 25, 2012

Comment 9:

The output in comment 8 is mysterious indeed. Let's at least make it clearer what is
happening. I would hope that since the first (only) directory in $GOPATH does not exist,
we should give an error about that instead of trying to invoke hg.

Labels changed: added priority-later, go1.1, removed priority-triage.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 10:

Labels changed: added size-s.

@kisielk
Copy link
Contributor

kisielk commented Jan 21, 2013

Comment 11:

On my Ubuntu system setting GOPATH="~/foobar" leads to some weird behaviour. With the
example above it seems the go tool creates $HOME/~/foobar/src/code.google.com/p, which
seems like the right thing to do (although slightly unexpected to some people...) if you
are not expanding the ~.
However as in the example above it when it calls the mercurial command:
hg clone -U https://code.google.com/p/go-tour ~/foobar/src/code.google.com/p/go-tour
the error message is:
abort: No such file or directory: /home/kamil/foobar/src/code.google.com/p/go-tour/.hg
which seems to imply that Mercurial does its own tilde expansion and so the paths don't
match.

@rsc
Copy link
Contributor

rsc commented Jan 22, 2013

Comment 12:

Let's just reject any GOPATH containing a ~ character.

@rsc
Copy link
Contributor

rsc commented Jan 31, 2013

Comment 13:

This issue was closed by revision 8b6534b.

Status changed to Fixed.

@gopherbot
Copy link
Author

Comment 14 by jrnieder:

This fix broke the build of a package sitting in the directory
/tmp/buildd/git-1.8.2~rc3/. Would a patch to only reject ~ at the beginning of GOPATH
and after : make sense?

@rsc
Copy link
Contributor

rsc commented Mar 14, 2013

Comment 15:

Will fix.

@rsc
Copy link
Contributor

rsc commented Mar 14, 2013

Comment 16:

This issue was closed by revision ffbcd89.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants