0

Can anyone guide, how to implement this linux command into a bash script

df --local -P | awk {'if (NR!=1) print $6'} | xargs -I '{}' find '{}' -xdev -type d -perm -0002 2>/dev/null | xargs chmod a+t
catty
  • 13
  • 3

1 Answers1

0

Simply

Put this in a file, add a shebang on 1st line:

#!/bin/sh

df --local -P |
    awk '{if (NR!=1) print $6}' |
    xargs -I '{}' find '{}' -xdev -type d -perm -0002 2>/dev/null |
    xargs --no-run-if-empty chmod a+t

But as this question is tagged :

Under , I would write this something like:

#!/bin/bash

{ read foo; mapfile -t mpoints;} < <(df --local -P)
TEXTDOMAIN=libc
exec 2> >(exec grep -v '^find: .*'$"Permission denied"\$ >&2)
find "${mpoints[@]#*% }" -xdev -type d -perm -0002 -exec chmod a+t {} +

Short, quick and efficient!

Explanation:

  • read foo just whipe header line of df output
  • mapfile -t take rest of df output into $mpoint array, (-t remove a trailing newline).
  • exec ... {} ... + will do approx same job than using xargs.
  • exec 2>... >&2 will silently delete lines matching regex in STDERR.
  • TEXTDOMAIN=libc and $"Permission denied" will localize message to make this script work in many languages.
F. Hauri - Give Up GitHub
  • 64,122
  • 17
  • 116
  • 137