我有两个都在终端中运行的命令:
notify-send "$(more /home/tim/autest.sh | head -1)"
和
notify-send "$(cat /home/tim/autest.sh | head -1)"
将它们放入这样的脚本中:
#! /bin/bash
notify-send "$(more /home/tim/autest.sh | head -1)"
notify-send "$(cat /home/tim/autest.sh | head -1)"
仍然给出两个输出,但只有一个是实际正确的输出:
更多的:
猫:
当我从终端运行时,它们都显示正确的输出。这是为什么?为什么从键盘快捷键触发时 more 没有给出正确的输出?
请注意,这不是问题notify-send
,它在回显到日志文件时会执行相同的操作:
#! /bin/bash
echo $(more /home/tim/autest.sh | head -1) > log1.txt
echo $(cat /home/tim/autest.sh | head -1) > log2.txt
日志1:
::::::::::::::
日志2:
#! /bin/bash
答案1
使用此命令:
notify-send "$(more /home/tim/autest.sh | head -4 | tail -1)"
当您使用带有快捷方式的脚本时,more
会出现以下情况:
::::::::::::::
/home/tim/autest.sh
::::::::::::::
#! /bin/bash
以下是源代码的摘录more.c
while (fnum < nfiles) {
if ((f = checkf (fnames[fnum], &clearit)) != NULL) {
context.line = context.chrctr = 0;
Currline = 0;
if (firstf) sigsetjmp (restore, 1);
if (firstf) {
firstf = 0;
if (srchopt) {
search (initbuf, f, 1);
if (noscroll)
left--;
}
else if (initopt)
skiplns (initline, f);
}
else if (fnum < nfiles && !no_tty) {
sigsetjmp (restore, 1);
left = command (fnames[fnum], f);
}
if (left != 0) {
if ((noscroll || clearit) && (file_size != LONG_MAX)) {
if (clreol)
home ();
else
doclear ();
}
if (prnames) {
if (bad_so)
erasep (0);
if (clreol)
cleareol ();
putsout("::::::::::::::");
if (promptlen > 14)
erasep (14);
putchar('\n');
if(clreol) cleareol();
puts(fnames[fnum]);
if(clreol) cleareol();
puts("::::::::::::::");
if (left > Lpp - 4)
left = Lpp - 4;
}
if (no_tty)
copy_file (f);
else {
within++;
screen(f, left);
within = 0;
}
}
sigsetjmp (restore, 1);
fflush(stdout);
fclose(f);
screen_start.line = screen_start.chrctr = 0L;
context.line = context.chrctr = 0L;
}
fnum++;
firstf = 0;
}