• [object Object]@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    2 months ago

    I have a script named d in my PATH and it contains this:

    ("$@" > /dev/null 2>&1 &)
    

    It allows me to run any program in a fully detached state in a way that works even if the terminal that started the program closes, and it’s as simple as d <command>.

      • [object Object]@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        2 months ago

        IIRC disown is a shell built-in command, so its use is a bit limited. Not sure if & is also a built-in, but I found disown to not work in some situations. Besides, it’s shorter.

        • stewie410@programming.dev
          link
          fedilink
          arrow-up
          1
          ·
          2 months ago

          shell built-in command

          After looking into it a bit more, its at least a builtin for bash but is otherwise not POSIX. I guess nohup ... & would be the POSIX compliant equivalent, though still not a builtin.

          Its my understanding that & backgrounds, not necessarily detaches, a process – if the parent process closes, I think the background tasks would still be wait()ed on, if only using &.

      • [object Object]@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        1
        ·
        2 months ago

        () creates a subshell, and & runs the command in background. The $@ means everything after the first argument, so the <command> is executed like a normal command. I am not sure why this works, but it has worked more consistently than nohup, disown, and it’s a lot shorter than most other solutions.

    • Victor@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      2 months ago

      What do y’all use awk for really? 20 of using Linux, I’ve never had to use awk. And I’ve done a looot of scripting in my days. Anything from building my own clone of polybar using eww (with loads of scripts underneath), to automated systems for bulk handling of student assignments back at uni when I used to help out with grading and such.

      What’s awk good for that other standard utilities can’t do?

      • Onno (VK6FLAB)@lemmy.radio
        link
        fedilink
        arrow-up
        1
        ·
        2 months ago

        I’ve been using Linux for 25 years, awk is a more recent addition to my arsenal, but rapidly becoming more and more useful.

        For example, awk is extremely helpful if you want to rearrange columns, do math on columns, essentially do things that would take multiple lines of bash with cut and read.