• ShaunaTheDead@kbin.social
    link
    fedilink
    arrow-up
    11
    ·
    8 months ago

    Serious question, what exactly does do do? In my terminal I can see that do is a command but all I get is bash: syntax error near unexpected token do’and obviously with such a common name it's hard to find information on google about whatdo` actually does.

    • ccf@lemmy.world
      link
      fedilink
      English
      arrow-up
      27
      ·
      edit-2
      8 months ago

      It’s used in loops in bash, like:

      for i in 1 2 3
      do 
          echo "$i"
      done 
      

      or

      while true
      do
          echo "o/"
      done
      
      • ShaunaTheDead@kbin.social
        link
        fedilink
        arrow-up
        3
        arrow-down
        1
        ·
        edit-2
        8 months ago

        But then why is it available in my command line terminal as a command that I can use? Like when I type do and then hit TAB twice to list commands that match the output is do done dofsck etc... but when I just enter do in the command line or do --help I get bash: syntax error near unexpected token 'do'

        I would assume that since I can run sudo apt update that I could also run do apt update where it would run it not as a super user. I know just apt update would do that too, but I’m just so curious if it’s possible to use do as a user-level sudo or what else it might be able to do.

        • somenonewho@feddit.de
          link
          fedilink
          arrow-up
          11
          ·
          8 months ago

          No do is not the “none superuser” version of sudo.

          As the comment above stated it’s part of loops. But since loop syntax are built in to bash they are actually seperate built-in commands. Because it’s an available builtin autocompletion offers it to you.

          The do command here is just a special command that expects a certain set of parameters and a done at the end this is why you get an error trying to run do alone because it’s not adhering to the syntax properly.

        • callyral [he/they]@pawb.social
          link
          fedilink
          English
          arrow-up
          1
          ·
          8 months ago

          i use doas and it has a -u user argument. by default the user is root but you could do doas -u another_user i guess. i don’t know if sudo has the same but it probably doas*.

          *i misspelled “does” but i’m keeping it