Temporary memory files and shell scripts

Posted on in Categories News last updated November 28, 2005

Recently we got lots of discussion about shell scripts that create a temporary memory files and only available to the invoked shell but not visible to any other user or process except root user. If we use /tmp directory to create file then it will be available to everyone. Next comes the idea of here document feature. For example following simple shell program uses here document feature

#!/bin/bash
cat << STOP
DATA1=””
DATA2=””
echo $DATA1
STOP

However soon we discovered that here documents is implemented as temporary file by bash shell. For example if we run strace on script we can easily see it is opening file in /tmp
$ strace -f script.bash

Bottom line if data is such critical scripts are useless, it is better go with private directory or write program in C.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Leave a Comment