0

I'm trying to execute this command on a remote computer using ssh.

ssh user@host "if [ $(ls -la /folder | wc -l) -eq 83 ]; then true; else false; fi;"

How can I make this part $(ls -la /folder | wc -l) to be executed on the remote computer instead of locally?

1
  • 1
    Use single quotes everywhere. Commented Sep 29, 2022 at 17:23

1 Answer 1

1

To prevent $() from being expanded locally, put it in single quotes:

ssh user@host 'if [ $(ls -la /path | wc -l) -eq 83 ]; then true; else false; fi;'

But you don't need the if/else, just do:

ssh user@host '[ $(ls -la /path | wc -l) -eq 83 ]'
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.