The /Data/*.jug: Not a directory
error message typically occurs when there are no files to be matched by the shell's glob expansion and the literal /Data/*.jug
is passed to a command that requires an existing file or directory as an argument.
Using the Bash
shell you can avoid this kind of error by using shopt -s nullglob
.
In addition, you should make sure that glob expansion is enabled (set +f
in Bash
).
Therefore explicitly use the Bash
shell with [task setLaunchPath: @"/bin/bash"];
and start testing your shell code with:
@"set +f; shopt -s nullglob; ls -ld /; find /Data/*.jug/files/ -name thefile"
Then add & test each further command of your given shell code step by step.
You may also use complete executable paths to be absolutely sure, e. g. /usr/bin/find
.
In your awk
command replace $1
with $0
in case there is a file name containing a space.
A possible source of confusion for the compiler may be the C-style comment start /*
in /Data/*.jug/files/
.
To get more output information use shell commands in verbose mode if possible, e. g. cp -v
and bash -xv -c
.
Your code worked for me on my machine with Mac OS X 10.6.8 using asynctask.m
from NSPipe - CocoaDev and /usr/bin/gcc-4.2
as compiler.
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath: @"/bin/bash"];
NSArray *arguments = [NSArray arrayWithObjects:
@"-xv",
@"-c",
@"set +f; shopt -s nullglob; ls -ld /noSuchFile; find /Data/*.jug/files/ -name thefile | head -n 1 | awk -v dir=\"$HOME/path/to/copy/to\" '{printf \"cp -v \\\"%s\\\" \\\"%s\\\"\\n\", $1, dir }' | bash -xv", nil];