Friday 30 August 2019

cat: -: No such file or directory

A weird error that took me a while to track down. I came across it in the iproute2 configure script which was setting the TMPDIR environment variable before using a cat heredoc statement (e.g. when you include some data in a shell script which demarked using markers - in this case 'EOF'):
TMPDIR=$(mktemp -d config.XXXXXX)
cat >test.c <<EOF
stuff and more stuff
EOF 
The problem is that the TMPDIR variable is used by the cat command. And in this case the TMPDIR is set to the output of mktemp which creates a temporary directory in the current working directory, but this is not usable by the cat command and results in the above error - it seems that cat command will only accept a TMPDIR if it is in /tmp and fails if it is set to another base directory?! According the man page mktemp is supposed to default to using /tmp but it's not working on Linux - It works fine on MacOS. Anyway so one just need to make the following change:
TMPDIR=$(mktemp -d /tmp/config.XXXXXX)

No comments:

Post a Comment