Creating variable in /tmp

Hi,

I am building a shell script (forgive me if this is the wrong place to post) which is supposed to create a temp directory in /tmp. The reason for this is to store bits of information such as application version, etc... that keeps my installation script current. I'm trying to create the following variable:

TMPDIR=/tmp/$$; export TMPDIR

And to give you all a better example, I have a line in my script (which was written and works in Linux btw - I am relatively new to mac) that checks the current version of the package to be installed through this script:

curl -O ${TMPDIR} "${URL}/current"

Current holds a binary that fires back the latest version number.

Anyways, any help that I could get with this would be greatly appreciated.

Thanks!

PowerMac G5, Mac OS X (10.5.7)

Posted on Jun 8, 2009 10:28 AM

Reply
4 replies

Jun 8, 2009 11:02 AM in response to tmcmurtr

It's not clear (to me, at least) what your question is.

Are you saying that you're creating your TMPDIR variable (e.g. via 'do shell script'), but your subsequent curl call doesn't see it.

If so, that's because each do shell script invocation is its own entity - therefore any environment variables created in a do shell script call are discarded when the shell command ends.

So you have two potential solutions.

One is to combine your two shell scripts into one do shell script command:

do shell script "TMPDIR=/tmp/$$; URL=\"http://www.some.com\"; curl -O ${TMPDIR} \"${URL}/current\""


(note the escaping for quotes, etc.

The second option is to setup the TMPDIR in one step and store the result in an AppleScript variable, then pass that back into the subsequent shell command:

set tmpdir to do shell script "TMPDIR=/tmp/$$; echo $TMPDIR"
-- additional AppleScript code
do shell script "curl -O " & tmpdir & "\"${URL}/current\""


In this way the first do shell script creates the tmpdir reference which is then passed in as an AppleScript variable into the second script.

Note that there are still several elements missing in this script. $$ relates to the PID of the process, so that will be different between the first and second do shell script commands.
If your goal is to have a unique, temporary directory then you may be better off using mktemp which will create a file (or directory) with a guaranteed unique name.

Jun 8, 2009 1:27 PM in response to Camelot

And yes you were also correct that the curl call does not see it. The problem that I run into is that the curl call is supposed to check the binary file for the current version and store it in TMPDIR. It then exports TMPDIR to a REV variable in a later call that adds the version extension to what is being downloaded.
Example:
curl -O ${WORK_DIR} "${URL}/${HOST PKG_PATH}${REV}.zip"

Now this works in the Linux environment, but curl is unable to retrieve REV from TMPDIR, so the url fails. This script is intended for multiple platforms, and this appears to be where it is failing in the terminal output, as the second curl call is trying to pull from an incomplete URL.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Creating variable in /tmp

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.