我想将一个 shell(在我的例子中:kornshell)的所有环境变量自动转移到另一个 shell(在我的例子中:z-shell)。
如果可能的话,传输应该在 zshell 的启动文件中,以避免使用额外的脚本,因为我想将它传输到其他服务器以达到同样的目的。
到目前为止我尝试过的:
放入$ export $(ksh -c env | tr '\n' ' ').zshrc (Zshell 的启动文件)。
这是行不通的,因为该命令是作为当前 shell (zsh) 的子级执行的,因此它具有与 zsh 相同的环境变量,而不是 kornshell 的环境。
在额外的脚本中
#!/usr/bin/ksh
echo $(ksh -c env | tr '\n' ' ') # for testing if it works
export $(ksh -c env | tr '\n' ' ')
Run Code Online (Sandbox Code Playgroud)
这也不行。
任何评论都非常感谢。
我正在尝试使用Google Guava构建缓存,并希望对过期的对象进行一些计算.如果删除了某个对象,removeListener会通知我.
如何在与主应用程序不同的线程中运行removeListener,或者将过期的对象(在下面的简单示例中,将是Integer 3)传递给处理计算的其他线程?
编辑:由于计算相当短,但经常发生,我宁愿不每次创建一个新线程(将是数千个线程),但有一个(或两个)计算所有对象.
简单的例子:
Cache<String, Integer> cache = CacheBuilder.newBuilder().maximumSize(100)
.expireAfterAccess(100, TimeUnit.NANOSECONDS)
.removalListener(new RemovalListener<String, Integer>() {
public void onRemoval(final RemovalNotification notification) {
if (notification.getCause() == RemovalCause.EXPIRED) {
System.out.println("removed " + notification.getValue());
// do calculation=> this should be in another thread
}
}
})
.build();
cache.put("test1", 3);
cache.cleanUp();
Run Code Online (Sandbox Code Playgroud)