2

I have two commands that both work in terminal:

notify-send "$(more /home/tim/autest.sh | head -1)"

and

notify-send "$(cat /home/tim/autest.sh | head -1)"

putting them in a script like this:

#! /bin/bash

notify-send "$(more /home/tim/autest.sh | head -1)"

notify-send "$(cat /home/tim/autest.sh | head -1)"

still gives two outputs, but only one is the actual correct output:

More:

enter image description here

Cat:

enter image description here

When I run from the terminal, they both show the correct output. Why is this? Why does more not give the correct output when triggered from a keyboard shortcut?

Note that this is not an issue with notify-send, it does the same thing when echoing to a log file:

#! /bin/bash

echo $(more /home/tim/autest.sh | head -1) > log1.txt

echo $(cat /home/tim/autest.sh | head -1) > log2.txt

Log1:

::::::::::::::

Log2:

#! /bin/bash
Tim
  • 32,861
  • 27
  • 118
  • 178

1 Answers1

3

Use this command:

notify-send "$(more /home/tim/autest.sh | head -4 | tail -1)"

When you use your script with a shortcut, more gives this:

::::::::::::::
/home/tim/autest.sh
::::::::::::::
#! /bin/bash

Here is an excerpt from the source code of 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;
}
A.B.
  • 90,397