Skip to main content


Laurence MorganAbout 1 min


Create a temporary file and write to it


tmp creates a temporary file, writes the contents of STDIN to it then returns its filename to STDOUT.

You can optionally specify a file extension, for example if the temporary file needs to be read by open or an editor which uses extensions to define syntax highlighting.


<stdin> -> tmp [ file-extension ] -> <stdout>


» out "Hello, world!" -> set tmp

» out $tmp

» open $tmp
Hello, world!


The temporary file name is a base64 encoded md5 hash of the time plus Murex function ID with Murex process ID appended:

package io

import (


func init() {
	lang.DefineMethod("tmp", cmdTempFile, types.Any, types.String)

func cmdTempFile(p *lang.Process) error {

	ext, _ := p.Parameters.String(0)
	if ext != "" {
		ext = "." + ext

	fileId := time.Now().String() + ":" + strconv.Itoa(int(p.Id))

	h := md5.New()
	_, err := h.Write([]byte(fileId))
	if err != nil {
		return err

	name := consts.TempDir + hex.EncodeToString(h.Sum(nil)) + "-" + strconv.Itoa(os.Getpid()) + ext

	file, err := os.Create(name)
	if err != nil {
		return err

	defer file.Close()

	_, err = io.Copy(file, p.Stdin)
	if err != nil {
		return err

	_, err = p.Stdout.Write([]byte(name))
	return err

This should should provide enough distance to run tmp in parallel....should you ever want to.

tmp files are also located inside a unique per-process Murex temp directory which itself is located in the appropriate temp directory for the host OS (eg $TMPDIR on macOS).

See Also

  • >> Append File: Writes STDIN to disk - appending contents if file already exists
  • open: Open a file with a preferred handler
  • pipe: Manage Murex named pipes
  • |> Truncate File: Writes STDIN to disk - overwriting contents if file already exists

This document was generated from builtins/core/io/tmp_doc.yamlopen in new window.

Last update:
Contributors: Laurence Morgan,Laurence Morgan,Olivier Refalo