我有兩個命令都可以在終端機中使用:
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;
}