{
  "path": "/posts/2019/2019-01-06-unix-files-with-spaces",
  "site": "at://did:plc:mracrip6qu3vw46nbewg44sm/site.standard.publication/self",
  "tags": [
    "code",
    "unix",
    "go"
  ],
  "$type": "site.standard.document",
  "title": "Go and UNIX files",
  "updatedAt": "2019-01-06T00:00:00.000Z",
  "publishedAt": "2019-01-06T00:00:00.000Z",
  "textContent": "I ran into an odd UNIX filename issue while writing Go code the other day.\n\nHere's a simplified example:\n\nLet's read a JSON file and unmarshal its contents into a struct in go. First, let's set an environment variable with our file name to avoid hardcoded constants in our program.\n\nNow, let's read the file into our struct:\n\nLooks like Go couldn't find my file.\n\nThe file definitely exists. What about its permissions?\n\nLooks like the file is readable by my program too. So, what is happening?\n\nI can see the file contents too.\n\nI am using the proper path. Let's check that Go is trying to read the correct file path.\n\nRunning the code:\n\nThe value of the environment variable seems to be correct.\n\nLet's see if we can find any weird characters hiding in the string:\n\nIt looks like there is an unexpected space showing up in  >/Users/dancorin/Desktop/test.json <. Where is this coming from?\n\nWhen we set our environment variable, it seems like we accidentally added a trailing space.\n\nGo is trying to tell us this:\n\nIt's just not _that_ obvious that there is a space in there. Something like the following could have helped:\n\nUNIX makes this issue a little more confusing because it has no problem allowing you to create filenames with trailing spaces. We can resolve our issue by running\n\nOr, better yet, we can fix our export command:\n\nI hope you never run into this one!",
  "canonicalUrl": "https://www.danielcorin.com/posts/2019/2019-01-06-unix-files-with-spaces"
}