I have a script that's supposed to get the list of files of two directories, get differences and execute some code for certain files.
These are the commands to get the file lists:
list_in=$(find input/ -maxdepth 1 - type f | sed 's/input\///' | sort -u);
list_out=$(find output/ -maxdepth 1 - type f | sed 's/output\///' | sort -u);
I execute the script in the correct directory, so this shouldn't fail. The unprocessed files are determined by
list_todo=$(comm -23 <(echo "$list_in") <(echo "$list_out"));
since the option -23
for comm
only prints lines of the first argument, that don't appear in both arguments and doesn't print lines that uniquely appear in the second argument.
However, only occasionally I get an error saying
command substitution: line 3: syntax error near unexpected token `('
command substitution: line 3: `comm -23 <(echo "$list_in") <(echo "$list_out")'
This really puzzles me, since the exact same script worked fine for the last 3 weeks. I'm using this on a cluster, so several processes might execute the script simultaneously. May the error be caused by this?
Update. The script is called with ./script
and I've obviously set chmod +x script
before.
(Disclaimer: Even though I'm working on a cluster and these first three lines of my script don't include any locking mechanisms: Of course, no file is ever processed twice)
bash file.sh
orchmod +x file.sh;./file.sh
because if you use sh it starts up in a special, POSIX-compliant mode and See here, #22: "process substitution is not available". – harish.venkat Jan 15 '13 at 17:57./file.sh
then you have shebang#!/bin/bash
just for clarification – harish.venkat Jan 15 '13 at 18:10#!/bin/bash
, the line to setlist_in
and the line to setlist_out
all above the line that setslist_todo
if that line is line 3. Also, just in case, put a space between the two closing parentheses, it's conceivable that some version of bash may want))
to close((
or$((
and not two separate)
s. – Gilles 'SO- stop being evil' Jan 16 '13 at 00:19#!bin/bash
in the first line, so the excerpts shown in the question are my actual script (except for the directory name input beeing data, but who cares). But as harish.venkat sais: calling with ./script has implicit /bin/bash shebang. The weird thing is that this isn't consistent behaviour. It obviously can't be complete crap since it worked for over 3 weeks now, meaning roughly 20000 successful runs.. – stefan Jan 16 '13 at 00:24./script
has an implicit#!/bin/sh
shebang, unless you run it from bash. – Gilles 'SO- stop being evil' Jan 16 '13 at 00:31bash script
. I'll report if the error is still occuring. – stefan Jan 16 '13 at 00:34