20.11 Set/get file permissions

Function: mbfl_file_enable_permissions

Declare the intention to use the programs required to get/set file permissions. Declaring the intention to use a program

The programs are: stat, chmod.

Function: mbfl_file_get_permissions PATHNAME
Function: mbfl_file_get_permissions_var _RV PATHNAME

Print the access permissions for PATHNAME, in octal format.

The function variant _var stores the result in the variable _RV, rather than print it; Result variables.

mbfl_file_get_permissions /bin/ls       -| 0755

mbfl_declare_varref(PERMS)
mbfl_file_get_permissions_var mbfl_datavar(PERMS) /bin/ls
"$PERMS" ⇒ 0755

To set permissions one may request the use of sudo: just request a user before invoking the following function. Executing a program

Function: mbfl_file_set_permissions MODE PATHNAME

Set the access permissions for PATHNAME; MODE must be in a form accepted by chmod.

Function: mbfl_file_chmod PERMISSIONS PATHNAME OPT

Execute the program chmod with PERMISSIONS as permissions arguments and PATHNAME as file system pathname argument. If the optional arguments OPT are present: they are inserted as command line options.

Function: mbfl_exec_chmod ARG

Execute the program chmod using the given optional arguments.

File access permissions conversion

The following functions implement a very limited conversion between symbolic and octal access permissions representations.

Function: mbfl_file_symbolic_to_octal_permissions MODE
Function: mbfl_system_symbolic_to_octal_permissions MODE

Convert three chars representing file permissions in a single octal digit.

mbfl_file_symbolic_to_octal_permissions 'rwx'
-| 7

mbfl_file_symbolic_to_octal_permissions 'r-x'
-| 5
Function: mbfl_file_octal_to_symbolic_permissions MODE
Function: mbfl_system_octal_to_symbolic_permissions MODE

Convert a single octal digit representing file permissions into three chars.

mbfl_file_octal_to_symbolic_permissions '7'
-| rwx

mbfl_file_octal_to_symbolic_permissions '5'
-| r-x

This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.