2

I'm trying to pass a windows command into a linux netcat shell and then read back the output.

So far I have:

cat <( printf 'ipconfig\n' )| nc -v 137.148.70.243 443

Which when copied and pasted into my pretty linux terminal gets the ip info from the connected windows machine.

However, when I try to call the same command via bash, I get the following error:

./DumpIP.sh: line n: syntax error near unexpected token `('

What gives?

EDIT

So if I try:

#!/bin/sh
cat <( printf 'ipconfig\n' )| nc -l

I get

./DumpCreds.sh: line 2: syntax error near unexpected token `('
./DumpCreds.sh: line 2: `cat <( printf 'ipconfig\n' )| nc -l'
7
  • "line n" ? it might help to see DumpIP.sh Commented Nov 14, 2016 at 21:05
  • 2
    why cat and printf? Use a simple echo ipconfig. Commented Nov 14, 2016 at 21:07
  • @JeffSchaller n is just a placeholder, sorry Commented Nov 14, 2016 at 21:15
  • Unable to replicate. Testing the exact line you have here (with a corresponding nc -l on the other side) works exactly as expected. Commented Nov 14, 2016 at 21:17
  • @DopeGhoti how strange, I've added my output verbatim in the question Commented Nov 14, 2016 at 21:36

1 Answer 1

6

Your problem is that you are invoking sh and not bash for your script in the shebang line. The syntactical convention of <(command) is a bashism that does not exist when invoked via sh, which emulates the POSIX shell (if /bin/sh is a symlink to /bin/bash).

2
  • Or, rather, is a bashism that is turned off when the Bourne Again shell is operating in its POSIX-compatibility mode. (Item #28 in the list in the doco.) After all, the questioner is not using the Bourne shell. Xe isn't even using the Almquist shell. Xe is using the Bourne Again shell. That's a Bourne Again shell error message. (Almquist and Korn shells present a different message.) Commented Nov 14, 2016 at 22:45
  • Also, there is no reason at all to use cat <( printf 'ipconfig\n' )| instead of just printf 'ipconfig\n'|. Commented Nov 14, 2016 at 23:50

You must log in to answer this question.