0

I'm trying to write a bash script to clone into a non-empty directory called ".janus". When I do this script:

#!/bin/bash

localFolder="~/.janus"
repository="git@github.com:aklt/plantuml-syntax.git"
git clone "$repository" "$localFolder"

I get the following error:

fatal: destination path '~/.janus' already exists and is not an empty directory.

What am I doing wrong? I can see if the plantuml-syntax directory already existed, but that is not the case.

If I then change the script to:

#!/bin/bash

localFolder="$HOME/.janus"
repository="git@github.com:aklt/plantuml-syntax.git"
git clone "$repository" "$localFolder"

I get the following error:

fatal: destination path '/Users/user/.janus' already exists and is not an empty directory.

Nona
  • 4,534
  • 6
  • 27
  • 57
  • BTW, you can't put spaces around the `=` in an assignment in shell. This is something http://shellcheck.net/ will catch. – Charles Duffy Jul 18 '17 at 21:04
  • BTW -- the code in the question doesn't include the actual clone operation, and thus doesn't generate the question included in the message. In the future, try to follow [mcve] guidelines. – Charles Duffy Jul 18 '17 at 21:06
  • I'm with @CharlesDuffy, we need to see the code. – addohm Jul 18 '17 at 21:09
  • oops, I pasted the wrong script - above is the corrected version – Nona Jul 18 '17 at 21:12
  • Looking at the updated version -- I'm guessing you're creating `'~/.janus'` with your script, and then inspecting `~/.janus` interactively, whereas the two aren't the same (because the former is under a directory named `~`, whereas the latter is in your home directory). – Charles Duffy Jul 18 '17 at 21:28
  • And the directory is actually empty, contrary to the error message? Please edit the question to show supporting evidence for that (ie. output from `ls -l ~/.janus`). – Charles Duffy Jul 19 '17 at 01:08
  • (BTW, if you replaced your `mkdir ~/.janus` with `rm -rf ~/.janus`, you'd moot the issue). – Charles Duffy Jul 19 '17 at 14:43

1 Answers1

2

Putting ~ in quotes means it loses its special meaning.

# ...you can either put that character **outside** the quotes...
mkdir ~"/.janus"

# ...or use $HOME instead.
localFolder="$HOME/.janus"
Charles Duffy
  • 235,655
  • 34
  • 305
  • 356
  • Even when I use $HOME, I still get a similar issue @CharlesDuffy (updated the question) – Nona Jul 18 '17 at 23:49
  • Please update the question further (to show how you're proving that the error message is incorrect -- which is to say, that the directory doesn't exist beforehand). – Charles Duffy Jul 19 '17 at 13:13