This looks like a dumb question. Everyone would simply do:
echo "$MYVAR" > myfile && chmod 400 myfile
A more cryptic way to this would be:
echo "$MYVAR" | install -m 400 /proc/self/fd/0 myfile
In this case, we need to echo a varible to stdout, the pipe will feed the stdin (which corresponds to /proc/self/fd/0
in linux) which will be read via proc filesystem by install.
In this case this might be not so useful, but for a simple create/copy of a dir/file it comes in handy:
install -m 700 -d ~/.ssh
install -m 644 /dev/null ~/.ssh/known_hosts