I try to make a join
from two sources — from a pipe and a file. I wrote this simple one-liner:
FILENAME=$TMPDIR".netstat"; \
join -t , $FILENAME <(nettop -t wifi -P -x -L1 | cut -d , -f 2,5,6 | tail -n +2) | \
awk '{print $0}'
It normally runs from the shell, but it doesn't run from a script.sh (full script see below):
./script.sh: line 16: syntax error near unexpected token `('
I tried to use different quotes inside my expression to mask variables, parameters or commands entirely, but I could not run the script.
Can anybody help?
P. S. This script is invoking by GeekTool (Shell widget) on macOS Sierra 10.12.3.
P.P.S. Yes, I know that OS X is not "Unix & Linux", but I thought the difference is not so great.
Full script with some comments is:
#!/bin/sh
FILENAME=$TMPDIR".netstat"
# checking if existing stats file
if [ ! -f $FILENAME ]; then
nettop -t wifi -P -x -L 1 | cut -d , -f 2,5,6 | tail -n +2 > $FILENAME # save stats to file
exit
fi
fts=`stat -r $FILENAME | cut -d " " -f 10` # get timestamp of stats file
now=`date +%s` # get current datetime
join -t, $FILENAME <(nettop -t wifi -P -x -L1 | cut -d , -f 2,5,6 | tail -n +2) | awk '{print $0}'
UPDATED. SOLVED
Shebang changed to #!/bin/bash