自己测试成功,记录一下, 因为这个好像不好现实.
参见 http://unix.stackexchange.com/questions/271963/in-inittab-trying-to-set-environment-variable-before-executing-script
Looking at the source code of the Linux sysvinit implementation, it does run a shell when it sees shell special characters, but it adds exec
before the string, which makes it possible to put redirections and use special characters in arguments but not to set an environment variable in this way.
} else if (strpbrk(proc, "~`!$^&*()=|\\{}[];\"'<>?")) { /* See if we need to fire off a shell for this command */ /* Give command line to shell */ args[1] = SHELL; args[2] = "-c"; strcpy(buf, "exec "); strncat(buf, proc, sizeof(buf) - strlen(buf) - 1); args[3] = buf; args[4] = NULL;
A straightforward solution would be to run env
.
scpt:234:once:env RSYNC_OPTIONS=-q /path/to/script/script.sh arg1 arg2 arg3 2>&1
Some possible workarounds to illustrate how to run an arbitrary command:
scpt:234:once:>&1; RSYNC_OPTIONS=-q exec /path/to/script/script.sh arg1 arg2 arg3 2>&1
scpt:234:once:2>&1; RSYNC_OPTIONS=-q exec /path/to/script/script.sh arg1 arg2 arg3
我使用这行:
null::respawn:2>&1; DISPLAY=:0.0 exec /bin/sysset
仅此记录.....