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
7
  • 2
    Works correctly for me, the two log files are exactly the same. Do you have some strange conf file/environment variable for more? (BTW, why not just head -1 /home/tim/autest.sh?)
    – Rmano
    Apr 23, 2015 at 19:56
  • @Rmano I'm asking because of this question + solution... askubuntu.com/questions/612979/…
    – Tim
    Apr 23, 2015 at 20:23
  • Does it work if you add -1 parameter to more ? It's supposed to limit screen size to one line Apr 23, 2015 at 20:41
  • still the ::::::::::::::
    – Tim
    Apr 23, 2015 at 20:46
  • Post the content of /home/tim/autest.sh.
    – A.B.
    Apr 24, 2015 at 10:14

1 Answer 1

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;
}
10
  • Will check at home
    – Tim
    Apr 24, 2015 at 12:41
  • @Tim And how does it look?
    – A.B.
    Apr 25, 2015 at 15:01
  • notify-send "$(more -u /home/tim/autest.sh | head -n 1)" works!
    – Tim
    Apr 25, 2015 at 15:14
  • @Tim You're confusing me, I think it does not work for you?
    – A.B.
    Apr 25, 2015 at 15:17
  • With the -u parameter it gives the correct output!
    – Tim
    Apr 25, 2015 at 15:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .