I have a script on my Mac Desktop: myProg.command or myProg.sh,

the content is:

cp "foo/foo.txt" "bar/foo.txt"

The script is set as executable.
The directories Desktop/foo, Desktop/bar and the file /Desktop/foo/foo.txt exist.

But when I double click on the executable, I see the error messages "command not found" and "no such file or directory".

The output is:

Last login: Mon Nov 25 15:56:19 on ttys000
CompName:~ MyName$ /Users/MyName/Desktop/myProg.command ; exit;
cp: foo/foo.txt
No such file or directory
: command not found/myProg.command: line 2: 
: command not found/myProg.command: line 3: 

[Process completed]

How can I fix that?

  • My guess would be that the script is run under a different directory - could you post the output of pwd? btw you know that task is trivial to do in Automator? – bdecaf Nov 25 '13 at 14:53
  • Well, for just 1 line of code I'd rather just use a script... – android_422 Nov 25 '13 at 15:01

When you launch a script like that it is always started in your HOME folder.
This is NOT your Desktop folder.
The Desktop is a sub-folder of HOME.

You can tell from the prompt-string in your output-example: "CompName:~ MyName$" is the current folder into which executing of the script starts.

  • How do I change the HOME folder from inside the script? How should the script be modified so that it works? – android_422 Nov 26 '13 at 10:43
  • @android_422 Huh ? You don't change the home-folder. You change the directory you are in with the cd command. "cd Desktop" as extra command before the copy. This is really basic stuff. You better Google for a basic Bash scripting course to get a little more background on this. – Tonny Nov 26 '13 at 11:04

I found where these error messages were coming from:

: command not found/myProg.command: line 2: 
: command not found/myProg.command: line 3: 

My file was created on a Windows PC with /r/n for line break. So apparently Mac was "thinking" the carriage return was a command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.