Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: in place editing by variables

by reisinge (Hermit)
on Apr 11, 2013 at 18:54 UTC ( [id://1028205]=note: print w/replies, xml ) Need Help??


in reply to in place editing by variables

I agree with hdb that it's safer (and easier) to use modules. Also consider using usermod --shell <new_shell> system command, on Linux, at least.

One way to replace the shell manually:

use strict; use warnings; my $new_shell = "/bin/nologin"; # in-place editing with backup $^I = ".bak"; # diamond operator "<>" reads from command line arguments or STDIN while ( my $line = <> ) { # skip empty lines next if $line =~ /^\s*$/; # split on ":" and return the 7th field (list slice) my $old_shell = ( split ":", $line )[6]; $line =~ s/$old_shell/$new_shell/; print "$line\n"; }

Update: using explicit variable $line instead of default variable $_ for better readability.

Well done is better than well said. -- Benjamin Franklin

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1028205]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-24 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found