将 VARS 传递到 Fedora 上的另一个控制台

将 VARS 传递到 Fedora 上的另一个控制台

我正在尝试从变量中定义的路径获取 config.sh 文件。如何让我的变量在当前控制台中展开。以下是我的命令:

[root@mysystem]#export AUTO_PATH="/mnt/share/__automation__"         
[root@mysystem]#runuser -l $(who | grep tty2 | awk -F " " '{print $1}') -c 'source $AUTO_PATH/config.sh;gnome-screensaver-command -d;xset dpms force on'

这些是我得到的输出:

-bash: /config.sh: No such file or directory
** Message: Failed to get session bus: Command line `dbus-launch --autolaunch=cb264e3a020119540fab776c00000007 --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed.\n
xset:  unable to open display ""

我在 Fedora 16 上运行,我试图在截屏之前关闭屏幕保护程序。我的$DISPLAY值存储在我的 config.sh 中

答案1

将单引号更改为双引号:

这:

-c 'source $AUTO_PATH/config.sh;gnome-screensaver-command -d;xset dpms force on'

应该是这样的:

-c "source $AUTO_PATH/config.sh;gnome-screensaver-command -d;xset dpms force on"

bash(1)手册页中:

 Enclosing characters in single quotes preserves the  literal  value  of
 each character within the quotes.  A single quote may not occur between
 single quotes, even when preceded by a backslash.

 Enclosing characters in double quotes preserves the  literal  value  of
 all  characters  within the quotes, with the exception of $, `, \, and,
 when history expansion is enabled, !.  The characters $  and  `  retain
 their  special meaning within double quotes.

这意味着任何$表达式(例如变量扩展)在双引号中时仍受尊重,但如果在单引号中则不受尊重。

相关内容