如何在.desktop文件的exec行中访问环境变量? [英] How do I access an environment variable in a .desktop file's exec line?

查看:648
本文介绍了如何在.desktop文件的exec行中访问环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序需要环境变量作为其参数之一的一部分:

My program requires an environment variable as part of one of its parameters:

myprogram --folder=$HOME/.special

但是,如果我将其放入.desktop文件的exec行中,它将无法正常工作:

However, if I put this into a .desktop file's exec line, it doesn't work:

Exec=myprogram --folder=$HOME/.special

$ HOME似乎什么也没解决.

The $HOME seems to resolve to nothing.

推荐答案

默认情况下,似乎并非所有实现都可以解析默认环境变量,但是您可以改为执行exec sh,它将解析传递的环境变量.请注意,桌面规范还要求您使用反斜杠转义=和$字符.所以你想要:

By default environment variables do not seem to be resolved by all implementations, however you can instead exec sh, which will resolve the passed environment variable. Note that the desktop spec also requires you to escape the = and $ character with a backslash. So you want:

Exec=sh -c "myprogram --folder\=\$HOME/.special"

有关需要转义的字符的完整列表,请参见规范

For the full list of characters that need escaping, see the specification

这篇关于如何在.desktop文件的exec行中访问环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆