Linux 如何访问 .desktop 文件的 exec 行中的环境变量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8980464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I access an environment variable in a .desktop file's exec line?
提问by Scott Ritchie
My program requires an environment variable as part of one of its parameters:
我的程序需要一个环境变量作为其参数之一的一部分:
myprogram --folder=$HOME/.special
However, if I put this into a .desktop file's exec line, it doesn't work:
但是,如果我将其放入 .desktop 文件的 exec 行,则它不起作用:
Exec=myprogram --folder=$HOME/.special
The $HOME seems to resolve to nothing.
$HOME 似乎没有解决。
采纳答案by Scott Ritchie
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,这将解析传递的环境变量。请注意,桌面规范还要求您使用反斜杠对 = 和 $ 字符进行转义。所以你要:
Exec=sh -c "myprogram --folder\=$HOME/.special"
For the full list of characters that need escaping, see the specification
有关需要转义的字符的完整列表,请参阅规范