I’m writing a simple ruby sandbox command-line utility to copy and unzip directories from a remote filesystem to a local scratch directory in order to unzip them and let users edit the files. I’m using Dir.mktmpdir as the default scratch directory, which gives a really ugly path (for example: /var/folders/zz/zzzivhrRnAmviuee+++1vE+++yo/-Tmp-/d20100311-70034-abz5zj)
I’d like the last action of the copy-and-unzip script to cd the calling shell into the new scratch directory so people can access it easily, but I can’t figure out how to change the PWD of the calling shell. One possibility is to have the utility print out the new path to stdout and then run the script as part of a subshell (i.e. cd $(sandbox my_dir) ), but I want to print out progress on the copy-and-unzipping since it can take up to 10 minutes, so this won’t work. Should I just have it go to a pre-determined, easy-to-find scratch directory? Does anyone have a better suggestion? Thanks in advance for your help. -Erik
You could die into a new shell that sits at your scratch dir, but I am having trouble understanding the point of all this. If your users are going to edit these files, then i suppose they either want to keep them or you are planning on working with the modified files. In the first case, put the files in a sensible location and you won’t have to worry about your users finding them (current working directory). In the second case, spawn a subshell for your users that sits in the scratch dir and instruct them to edit the files. When the subshell exits you can continue to process your files from the same ruby program.