vi /tmp/jerry.$$"/tmp/jerry.12345" [New file] %
The shell replaces
$$ with the shell's
(in this case,
If you use a
$$ won't work for you.
In that case, just pick a unique name.
You could use today's date instead.
To give yourself both options with a minimum of work, here are lines for your. The left column has lines for csh-like shells, and the right is for sh-like shells.
.cshrc: .profile: set tf=/tmp/jp$$ tf=/tmp/jp$$ .login: export TF set date = (`date`) set `date` setenv TF /tmp/jp$date TF=/tmp/jp$4
(The last two lines grab the fourth word - the current time - from the output of thecommand.) When I want a temporary file in my current shell, I type:
The shell expands the
$tf-1 into a filename like
$tf-* expands into all my temporary files in this shell.
Usually, that's great. But if I go to a subshell, do a shell escape,
and so on, the temporary files I make with
$tf won't be the
same as the ones I make in my login shell because the PIDs are
different. If I need them to be the same, I use
It's set to the time I logged in.
And because environment variables are passed to child shells, the name
(like /tmp/jp09:34:56) will be the same in subshells:
If I'll be using a file for more than a minute or two, I might forget
what's in which file.
So I leave myself a note in shell variables named
and environment variables named
n-where "xf" means
"explain file" and
1, 2, etc. to correspond to the variable.
If I don't remember which have what, I get a list by piping the output of
set (for shell variables) or
(for environment variables) through grep.
sort -t: +2 $tf-2 > $tf-3%
set xf3='sorted list of chapter 21 files'...later... %
set | grep xfxf1 sorted list of chapter 20 files xf3 sorted list of chapter 21 files %
|To clean up when I log out, I added the lines that follow to the C shell .logout file. The Bourne shell version is similar, but it needs a couple of tricks to work on some shells; it's on the CD-ROM.|
# CLEAN FILES (IF ANY) OUT OF /tmp: set nonomatch set tmpf="\`ls -d $tf-* $TF-* |& grep -v ' not found'\`" if ( "$tmpf" =~ ?* ) then echo; echo "Your files in /tmp:" ls -d $tmpf echo -n "'rm -rf' them? [ny](n) " if ( "$<" =~ y* ) rm -rf $tmpf endif
If I made any temporary files from my login shell or any subshells, I get this message when I log out:
logoutYour files in /tmp: /tmp/jp2345-1 /tmp/jp2345-2 /tmp/jp2748-1 /tmp/09:23:45-1 'rm -rf' them?
Another way to do this is with a script like.