Tricking Linux apps about current time with environment variables

Posted by geek on Super User See other posts from Super User or by geek
Published on 2010-05-21T17:23:18Z Indexed on 2010/05/21 17:32 UTC
Read the original article Hit count: 168

Sometimes it is possible to trick a Linux app by calling it like this:

HOME=/tmp/foo myapp

This would make myapp think /tmp/foo is the home directory, it won't try to get the user id, find its home directory via getpwent().

This is useful when myapp must be forced to dump some of its config files into a non-standard location different than ~.

A similar trick can be done like this:

LANG=foo LC_ALL=bar myapp

This is useful when myapp needs to be called once with a different locale without having to make the change persistent by using the export bash built-in or even modify stuff in /etc/profile.

Is it possible to pull the same trick with time and date? The goal is to make an app use another time than the system ones. The final goal - to make timestamps that appear in logs/commit messages not being tied to the system time.

© Super User or respective owner

Related posts about linux

Related posts about environment-variables