1

Whatever the umask value I want to change it into umask 077 dynamically.

sed -d 's/umask [0-999]/umask 077/g' /etc/bashrc, 

I have tried the above one but it's not working.

Biffen
  • 6,249
  • 6
  • 28
  • 36
Manikandan
  • 49
  • 2
  • 6

1 Answers1

0

You can use

sed -i 's/\(umask \)[0-9]\{1,\}/\1 077/g' /etc/bashrc

It means

  • -i - the /etc/bashrc will be changed inline
  • \(umask \)[0-9]\{1,\} - the regex pattern that matches
    • \(umask \) - Group 1: umask + space
    • [0-9]\{1,\} - 1 or more occurrences of any ASCII digit
  • \1 077 - the contents of Group 1, space, 077
  • g' - global` modifier, match and replace all non-overlapping occurrences.
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563