Created
February 16, 2018 16:51
-
-
Save realeroberto/8b61441d97842544888d18106c4111da to your computer and use it in GitHub Desktop.
Convert a file mode string into the octal value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Convert a file mode string (e.g., -rw-rw-r--) into the octal value | |
function perm2octal() | |
{ | |
local perm=${1:1} # remove first char (the file type) | |
res=$(echo "$perm" | sed 's/[^-]/1/g; s/-/0/g') | |
res=$(echo "ibase=2; obase=8; $res" | bc) | |
echo "$res" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment