while循环似乎不记得变量更新-不涉及管道

多项式

我正在使用标准Mate桌面运行LMDE 2('Betsy'),并且具有以下脚本:

#!/bin/bash
# This script starts a specified terminal-binary in "Always on Top"-mode
# The assumption is, that 'wmctrl -l' sorts windows with the 
# in such a way, that the more recently a window has been created, 
# the lower it will be on the list ( compared to windows with the 
# same title).
#
# This is my assumption based on a short observation. The window 
# ids are probably given out in ascending hex numbers
# 
# Note: Using the pid will not help, since all terminals seem to
# be having the same pid
term_title_def='Terminal'
term_title='Terminal_top'
term_cmd="mate-terminal --title=$term_title"

# start terminal, wait for window  to appear and get id of most recently created window
# NOTE: a possible wrap-around of window ids has not been considered here!
eval $term_cmd
win_id=''
while [[ -z $win_id ]]; do
    win_id=$(wmctrl -l | grep "[[:blank:]]$term_title\$" | tail -n 1 | awk '{ print $1 }')
done

# DEBUG
touch /tmp/$win_id

# rename, set as "Always on top"
wmctrl -ir $win_id -T "$term_title_def"
wmctrl -ir $win_id -b add,above
wmctrl -ia $win_id

不知何故,脚本ps aufx在重启后首次从MATE-panel链接运行时,永远不会退出while循环(用进行检查)。后续调用按预期方式工作,即该链接完成了我想要的操作(请参阅上面的脚本注释)。

因此,我猜想在启动MATE之后立即以某种方式win_id无法在while-test中正确展开或类似的东西。

这是为什么?
我现在将尝试类似的方法while true; do stuff; break; done,希望它能起作用...

更新:用以下内容
替换while上面-loop

while true; do
    win_id=$(wmctrl -l | grep "[[:blank:]]$term_title\$" | tail -n 1 | awk '{ print $1 }')
    [[ $win_id ]] && break
done

没有改变任何东西。脚本仍然陷入无限循环...

芒登

我不知道这怎么工作。当你跑步

eval $term_cmd 

您将打开一个终端窗口,脚本将不会执行任何其他操作,除非您将其关闭。您需要的是:

$term_cmd &

在后台运行它(不要使用eval,它是不需要的)。然后,您也不需要选择wmctrl输出的最后一行。,您正在设置终端标题,因此将其设置为唯一的grep内容:

#!/bin/bash
# This script starts a specified terminal-binary in "Always on Top"-mode
# The assumption is, that 'wmctrl -l' sorts windows with the 
# in such a way, that the more recently a window has been created, 
# the lower it will be on the list ( compared to windows with the 
# same title).
#
# This is my assumption based on a short observation. The window 
# ids are probably given out in ascending hex numbers
# 
# Note: Using the pid will not help, since all terminals seem to
# be having the same pid
term_title_def='Terminal'
term_title="Terminal_top_$$" ## Use the script's PID for a unique title
term_cmd="mate-terminal --title=$term_title"

## Start terminal. No need to wait, the loop will run until
## the terminal has been opened
$term_cmd &

win_id=''

while [[ -z "$win_id" ]]; do
    ## No need for '[[:blank:]]' and \$, you are using a unique title,
    ## keep the regex general. 
    win_id=$(wmctrl -l | grep "$term_title" | awk '{ print $1 }')
done
# DEBUG
touch /tmp/$win_id

# rename, set as "Always on top"
wmctrl -ir $win_id -T "$term_title_def"
wmctrl -ir $win_id -b add,above
wmctrl -ia $win_id

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

do-while循环不记得while中的变量

来自分类Dev

如何在管道中涉及的FOR循环中设置变量?

来自分类Dev

在 jQuery 中启动 POST 方法而不涉及任何输入变量

来自分类Dev

Heroku 管道推广不更新 github

来自分类Dev

Python的while循环不更新

来自分类Dev

当似乎不涉及“ long”类型时,无法将“ long”类型隐式转换为“ int”

来自分类Dev

在不涉及循环的情况下,在很长的过程中将数据帧指向磁盘

来自分类Dev

的解释-不涉及反思

来自分类Dev

为什么shell不设置通过管道传递的变量?

来自分类Dev

整数变量不遵循while循环条件

来自分类Dev

变量不更新通过csv文件循环

来自分类Dev

为什么在循环中涉及异步调用的递归函数不返回到调用者函数以继续循环?

来自分类Dev

Bash-我的脚本不记得变量

来自分类Dev

while循环中的变量在for循环后不增加

来自分类Dev

TortoiseGit不记得密码

来自分类Dev

Ubuntu 不记得设置

来自分类Dev

不涉及继承的虚函数

来自分类Dev

if 语句涉及变量的位移 - 错误与否(更新)

来自分类Dev

涉及for循环的前叉功能

来自分类Dev

设置变量以捕获while循环中的组而不更改$ 1

来自分类Dev

计数器变量在 do while 循环内不递增

来自分类Dev

涉及变量的奇怪行为

来自分类Dev

jQuery Each循环不更新变量中的HTML

来自分类Dev

为什么我的for循环不更新给定变量?

来自分类Dev

如何创建在此循环中不更新的变量?

来自分类Dev

jQuery Each循环不更新变量中的HTML

来自分类Dev

为什么我的for循环不更新给定变量?

来自分类Dev

在变量中执行命令不执行管道的后半部分

来自分类Dev

Ng-Model不更新输入标签中的对象(在具有键值管道的ngFor内部)

Related 相关文章

热门标签

归档