The title, basically. I've seen it used in some progs, like here to do something if the output of a command contains some text:
#!/bin/bash
tmp=/tmp/t$$
mycommand > $tmp
if grep -q 'Mytext' $tmp
then
action
fi
rm -f $tmp
exit 0
I find it very usefull, and started using it, but I don't like using thing I don't really understand. Two things are unclear for me here:
- what the
tmp=/tmp/t$$exactly does (what is thatt$$thing?? The double dollar really confuse me) - How does the
$tmpworks? I mean, I get that we can put the output of the command in$tmpjust as if we were writing it to a file (and find it better with$tmp, without creating temporary files), but when we delete it withrm $tmp, what exactly happens? Is there a temporary file namedt$$in/tmpthat got deleted?
I couldn't find an answer online and I really would like to understand it.
The double-dollar is the process-id of the current shell.
The script above sets the variable "tmp" to the "/tmp/t123456" (where 123456 is the process id of the current running script).
I think the "t" is just a string the author chose to use.
Another approach could be to do something like:
-Scott