0

Checking for the existence of a directory which should resolve to ~/code/devtools/deploy-mix.

This if statement doesn't pass -- though I can cd ~/code/devtools/deploy-mix. Plz help with bash syntax :)

GIT_DIR="$HOME/code"
if [ -d "${GIT_DIR}/devtools/deploy-mix" ]; then
    echo "found $GIT_DIR/devtools/deploy-mix"
fi

output:

sh -x script

'[' -d '$HOME/code/devtools/deploy-mix' ']'

I'd love to give out some internet karma for this one and I'm ok if you decide to call me a noob (sometimes the coding angle doesn't sit on your shoulder).

Manchego
  • 755
  • 1
  • 6
  • 14

1 Answers1

1

Replace ~ by $HOME or remove quotes.

Examples:

GIT_DIR="$HOME/code"
GIT_DIR=~/'code'
Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • Might be worth being more clear about *which* quotes to remove. The `GIT_DIR='~/code'` quotes are bad; the `[ -d "${GIT_DIR}" ]` quotes are good. – Charles Duffy Aug 19 '15 at 23:35
  • GIT_DIR="$HOME/code" if [ -d "${GIT_DIR}/devtools/deploy-mix" ]; then echo "found $GIT_DIR/devtools/deploy-mix" fi sh -x '[' -d '$HOME/code/devtools/deploy-mix' ']' – Manchego Aug 19 '15 at 23:48