1

Right now I have this file so far...

#!/usr/bin/env bash

DIRECTORY=$1

ssh [email protected] "$( cat <<'EOT'
cd /web/$DIRECTORY || exit
pwd
unset GIT_DIR
git log --oneline -n 10 --decorate
git branch
EOT
)";

Why does the pwd just print out "/web/"? It doesn't actually seem to be using my variable. Then all the git commands throw errors about being in the web directory.

If I have it echo $DIRECTORY out before ssh-ing, it echos out my variable, but refuses to pass it through to the ssh command?

1 Answer 1

3

This happens because you quote the here doc delimiter. Here's POSIX:

If any character in word is quoted, the delimiter is formed by performing quote removal on word, and the here-document lines will not be expanded. Otherwise, the delimiter is the word itself.

And here's an example:

#!/bin/bash
var=42

cat << 'end'
With quotes: $var and \$var
end

cat << end
Without quotes: $var and \$var
end

When executed:

With quotes: $var and \$var
Without quotes: 42 and $var
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.