0

I'm creating a .command file (with macOS) that I want to be able to drop into any folder and have it create a .txt file relative to what ever folder it exists in.

Eg.

cd .
echo -e "write this to the log" >> log.txt
exit

The above doesn't work though. I've also tried cd pwd.

Is this possible to do?

JCraine
  • 1,159
  • 2
  • 20
  • 38
  • "cd pwd" doesn't make any sense, since you are already in the current dir. What's your true purpose? Give us some examples, so that we can figure out your problem. – NeilWang May 19 '19 at 08:17
  • The "current directory" is not generally the directory the script is located in; it's inherited from the current working directory of the process that ran the script, so it could be almost anything. If you double-click a .command script in macOS, it's run by a process whose working directory is your home folder. For the script's folder, see ["Referring to a file relative to executing script"](https://stackoverflow.com/questions/6659689/referring-to-a-file-relative-to-executing-script), and [BashFAQ #28](http://mywiki.wooledge.org/BashFAQ/028). – Gordon Davisson May 19 '19 at 08:35

0 Answers0