• sed -i '/%sudo/c %sudo ALL=(ALL:ALL) NOPASSWD:ALL' /etc/sudoers

    From [email protected]@21:1/5 to All on Mon Sep 18 22:04:14 2023
    I noticed the following usage here [1]:

    sed -i '/%sudo/c %sudo ALL=(ALL:ALL) NOPASSWD:ALL' /etc/sudoers
    visudo -c

    But I'm puzzled by the `c' that appeared in the `/%sudo/c' part of the sed command above. Any tips will be helpful.

    [1] https://blog.51cto.com/u_4820306/5425575

    Regards,
    Zhao

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Keith Thompson@21:1/5 to [email protected] on Mon Sep 18 23:10:33 2023
    "[email protected]" <[email protected]> writes:
    I noticed the following usage here [1]:

    sed -i '/%sudo/c %sudo ALL=(ALL:ALL) NOPASSWD:ALL' /etc/sudoers
    visudo -c

    But I'm puzzled by the `c' that appeared in the `/%sudo/c' part of the sed command above. Any tips will be helpful.

    [1] https://blog.51cto.com/u_4820306/5425575

    The 'c' command is a GNU extension. Type "info sed" for documentation,
    or search online for GNU sed documentation if you don't have it
    installed locally.

    (Seriously, I wonder why checking the documentation wasn't your first
    thought before posting here.)

    --
    Keith Thompson (The_Other_Keith) [email protected]
    Will write code for food.
    void Void(void) { Void(); } /* The recursive call of the void */

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Elvidge@21:1/5 to Keith Thompson on Tue Sep 19 11:19:27 2023
    On 19/09/2023 07:10, Keith Thompson wrote:
    "[email protected]" <[email protected]> writes:
    I noticed the following usage here [1]:

    sed -i '/%sudo/c %sudo ALL=(ALL:ALL) NOPASSWD:ALL' /etc/sudoers
    visudo -c

    But I'm puzzled by the `c' that appeared in the `/%sudo/c' part of the sed command above. Any tips will be helpful.

    [1] https://blog.51cto.com/u_4820306/5425575

    The 'c' command is a GNU extension. Type "info sed" for documentation,
    or search online for GNU sed documentation if you don't have it
    installed locally.

    (Seriously, I wonder why checking the documentation wasn't your first
    thought before posting here.)


    Seriously, you're asking hongyi to check the documentation?


    --
    Chris Elvidge, England
    I WILL NOT USE ABBREV.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andy Walker@21:1/5 to Keith Thompson on Tue Sep 19 11:30:16 2023
    On 19/09/2023 07:10, Keith Thompson wrote:
    [Sed:]
    The 'c' command is a GNU extension.

    The "c" /command/ was "original", and is in 7th Edition Unix.
    But originally it had to be followed /immediately/ by a backslash,
    with the replacement text on the following line(s). On my current
    [Linux] machine, "man sed" shows optional space(s) between "c" and
    the backslash [which is presumably the GNU extension, as it's an
    obvious change to make on a re-write]. But it doesn't show the extra
    [also obvious] possibility of the replacement text on the same line,
    for which, as you suggest, you need "info sed".

    Personally, I prefer "man" to "info", if available, as the
    output is formatted nicely, so it's understandable that the extra
    extension should be overlooked. OTOH, once spaces are allowed, it's
    harder to exclude the same-line extensions to "a", "c" and "i" than
    to allow them, so perhaps the documentation should emphasise the
    same-line version and then point out the usefulness of backslashes.

    [To Zhao:]
    (Seriously, I wonder why checking the documentation wasn't your first
    thought before posting here.)

    Perhaps he enjoys getting a rise out of people who wonder why
    he prefers asking here to checking elsewhere? It's not as though this
    is the first example of its type over the past decade and more.

    --
    Andy Walker, Nottingham.
    Andy's music pages: www.cuboid.me.uk/andy/Music
    Composer of the day: www.cuboid.me.uk/andy/Music/Composers/Praetorius

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jim@21:1/5 to Andy Walker on Tue Sep 19 13:54:05 2023
    On Tue, 19 Sep 2023 11:30:16 +0100, Andy Walker wrote:

    On 19/09/2023 07:10, Keith Thompson wrote:

    [To Zhao:]
    (Seriously, I wonder why checking the documentation wasn't your first
    thought before posting here.)

    Perhaps he enjoys getting a rise out of people who wonder why
    he prefers asking here to checking elsewhere? It's not as though this
    is the first example of its type over the past decade and more.

    Hongi's general knowledge of English in the subject area of concern
    may not match your general knowledge of English in it.

    What you find easy to understand or obvious from reading the man
    and info texts may not be as easy or obvious for Hongi.

    On an interactive forum, one can persist in trying to clarify
    one's understanding.

    Cheers!

    jim b.



    --
    UNIX is not user-unfriendly, it merely
    expects users to be computer friendly.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to [email protected] on Tue Sep 19 16:37:23 2023
    On Wednesday, September 20, 2023 at 7:27:12 AM UTC+8, [email protected] wrote:
    On Tuesday, September 19, 2023 at 2:10:42 PM UTC+8, Keith Thompson wrote:
    "[email protected]" <[email protected]> writes:
    I noticed the following usage here [1]:

    sed -i '/%sudo/c %sudo ALL=(ALL:ALL) NOPASSWD:ALL' /etc/sudoers
    visudo -c

    But I'm puzzled by the `c' that appeared in the `/%sudo/c' part of the sed command above. Any tips will be helpful.

    [1] https://blog.51cto.com/u_4820306/5425575
    The 'c' command is a GNU extension. Type "info sed" for documentation,
    or search online for GNU sed documentation if you don't have it
    installed locally.

    (Seriously, I wonder why checking the documentation wasn't your first thought before posting here.)
    See the following documentation on my machine and the corresponding tests:

    The OS and sed info:

    werner@X10DAi:~$ lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description: Ubuntu 22.04.3 LTS
    Release: 22.04
    Codename: jammy

    werner@X10DAi:~$ sed --version | head -1
    sed (GNU sed) 4.8


    info sed:

    'c\'
    'TEXT'
    Replace (change) lines with TEXT.

    'c TEXT'
    Replace (change) lines with TEXT (alternative syntax).

    man sed:

    c \

    text Replace the selected lines with text, which has each embed‐
    ded newline preceded by a backslash.


    Further tests based on the above documentation:

    werner@X10DAi:~$ sed -n '/foo/c bar' <<< foo
    bar
    werner@X10DAi:~$ sed -n '/foo/cbar' <<< foo
    bar
    werner@X10DAi:~$ sed -n '/foo/c\ bar' <<< foo
    bar
    werner@X10DAi:~$ sed -n '/foo/c \ bar' <<< foo
    bar
    werner@X10DAi:~$ sed -n '/foo/c \
    bar' <<< foo
    bar
    werner@X10DAi:~$ sed -n '/foo/c \
    bar' <<< foo
    bar

    And, I am still puzzled by the following result:

    werner@X10DAi:~$ sed -n '/foo/c\
    \bar' <<< foo
    bar

    Why doesn't it give `\bar'?


    Therefore, the explanation of the documentation is not very adequate.

    Zhao
    --
    Keith Thompson (The_Other_Keith) [email protected]
    Will write code for food.
    void Void(void) { Void(); } /* The recursive call of the void */

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to Keith Thompson on Tue Sep 19 16:27:08 2023
    On Tuesday, September 19, 2023 at 2:10:42 PM UTC+8, Keith Thompson wrote:
    "[email protected]" <[email protected]> writes:
    I noticed the following usage here [1]:

    sed -i '/%sudo/c %sudo ALL=(ALL:ALL) NOPASSWD:ALL' /etc/sudoers
    visudo -c

    But I'm puzzled by the `c' that appeared in the `/%sudo/c' part of the sed command above. Any tips will be helpful.

    [1] https://blog.51cto.com/u_4820306/5425575
    The 'c' command is a GNU extension. Type "info sed" for documentation,
    or search online for GNU sed documentation if you don't have it
    installed locally.

    (Seriously, I wonder why checking the documentation wasn't your first thought before posting here.)

    See the following documentation on my machine and the corresponding tests:

    The OS and sed info:

    werner@X10DAi:~$ lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description: Ubuntu 22.04.3 LTS
    Release: 22.04
    Codename: jammy

    werner@X10DAi:~$ sed --version | head -1
    sed (GNU sed) 4.8


    info sed:

    'c\'
    'TEXT'
    Replace (change) lines with TEXT.

    'c TEXT'
    Replace (change) lines with TEXT (alternative syntax).

    man sed:

    c \

    text Replace the selected lines with text, which has each embed‐
    ded newline preceded by a backslash.


    Further tests based on the above documentation:

    werner@X10DAi:~$ sed -n '/foo/c bar' <<< foo
    bar
    werner@X10DAi:~$ sed -n '/foo/cbar' <<< foo
    bar
    werner@X10DAi:~$ sed -n '/foo/c\ bar' <<< foo
    bar
    werner@X10DAi:~$ sed -n '/foo/c \ bar' <<< foo
    bar
    werner@X10DAi:~$ sed -n '/foo/c \
    bar' <<< foo
    bar
    werner@X10DAi:~$ sed -n '/foo/c \
    bar' <<< foo
    bar


    Therefore, the explanation of the documentation is not very adequate.

    Zhao

    --
    Keith Thompson (The_Other_Keith) [email protected]
    Will write code for food.
    void Void(void) { Void(); } /* The recursive call of the void */

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Keith Thompson@21:1/5 to [email protected] on Tue Sep 19 17:21:04 2023
    "[email protected]" <[email protected]> writes:
    On Tuesday, September 19, 2023 at 2:10:42 PM UTC+8, Keith Thompson wrote:
    "[email protected]" <[email protected]> writes:
    I noticed the following usage here [1]:

    sed -i '/%sudo/c %sudo ALL=(ALL:ALL) NOPASSWD:ALL' /etc/sudoers
    visudo -c

    But I'm puzzled by the `c' that appeared in the `/%sudo/c' part of the sed command above. Any tips will be helpful.

    [1] https://blog.51cto.com/u_4820306/5425575
    The 'c' command is a GNU extension. Type "info sed" for documentation,
    or search online for GNU sed documentation if you don't have it
    installed locally.

    (Seriously, I wonder why checking the documentation wasn't your first
    thought before posting here.)

    See the following documentation on my machine and the corresponding tests:
    [SNIP]
    Therefore, the explanation of the documentation is not very adequate.

    I see that the explanation in `info sed` is clear enough to explain the behavior of the sed command you showed in the parent article. (Each
    line containing "%sudo" is replaced with the specified text. You could
    use the 's' command to do the same thing, perhaps more clearly, since
    the 'c' command is a bit obscure IMHO.)

    (`man sed` is missing this information, but the "SEE ALSO" section
    at the bottom says the man page is incomplete. This is usually
    the case for GNU software.)

    I'd just edit the file manually using `visudo`, but maybe you want to do
    this on a lot of systems and want to automate it.

    You might also consider first running the sed command on a copy of your
    sudoers file so you don't risk breaking anything.

    If you want to ask about something like this please (1) let us know that
    you actually checked the documentation before posting (it was reasonable
    to assume that you hadn't bothered) and (2) if you find the
    documentation unclear, let us know what you find unclear about it.

    --
    Keith Thompson (The_Other_Keith) [email protected]
    Will write code for food.
    void Void(void) { Void(); } /* The recursive call of the void */

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)