1

I'm trying to query the contents of a log file on a remote server, however, I can't seem to get it to work.

#!/bin/bash
while read line; do
        echo "Do stuff to the file, line by line"
done < ( ssh -n user@server "cat /path/to/file" )

I get a syntax error at the first parenthesis. If I remove the parenthesis, I get a syntax error at the "-n" flag.

Everything works properly from the shell, so I'm assuming there is some behavior here that I'm not understanding correctly.

Thanks!

1 Answer 1

4

You need another < for the process substitution.

#!/bin/bash
while read line; do
        echo "Do stuff to the file, line by line"
done < <( ssh -n user@server "cat /path/to/file" )

The first < specifies the input redirection. The <(...) construct is the process substitution, which is similar to command substitution, but treated the output of the enclosed command as a file, rather than a string.

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.