Skip to content

Files

Latest commit

 

History

History
28 lines (17 loc) · 908 Bytes

SC2174.md

File metadata and controls

28 lines (17 loc) · 908 Bytes

Pattern: Use of unexpected mkdir -pm

Issue: -

Description

When using -m 0755, the mode of the directory created will be set to 0755. When using -p, parent directories which do not exist will be created, but the mode specified by -m will only be used on the last directory. The parent directories will get their access mode the default way, via umask().

Example of incorrect code:

mkdir -p -m 0755 foo/bar/baz

Example of correct code:

mkdir -p foo/bar/baz
chmod 0755 foo/bar/baz foo/bar foo

Exceptions

ShellCheck does not warn if the path only has one component, as in mkdir -p -m 0755 somedir, but will not attempt to determine whether this applies for a variable as in mkdir -p -m 0755 "$somedir". You can mkdir/chmod separately or ignore this message.

Further Reading