0
localhost:~ $ df -k / | awk '{print $3/1024/1024/1024}'
0
0.00618061

localhost:~ $ ssh localhost "df -k / | awk '{print $3/1024/1024/1024}'"
01
01

marked as duplicate by Michael Homer, Archemar, chaos, Gilles ssh Jul 24 '15 at 22:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $3 is being substituted in your shell, before ssh sees it. – Michael Homer Jul 24 '15 at 7:22
  • @MichaelHomer is right - what your localhost sees is df -k / | awk '{print /1024/1024/1024}' – amisax Jul 24 '15 at 7:27
2

You need more quoting when you pass arguments to SSH. Try this:

ssh localhost "df -k / | awk '{print \$3/1024/1024/1024}'"
0
0.00623375

Note the \ before $3.

Not the answer you're looking for? Browse other questions tagged or ask your own question.