Skip to content

Instantly share code, notes, and snippets.

@Taresin
Last active July 6, 2023 11:17
Show Gist options
  • Save Taresin/59042d3cd000c7f760aaac40d772ed41 to your computer and use it in GitHub Desktop.
Save Taresin/59042d3cd000c7f760aaac40d772ed41 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Creates a file called test.txt
FILE_NAME="chmod_game.txt"
get_random() {
shuf -i 0-$1 -n 1
}
owner=$(get_random 7)
group=$(get_random 7)
world=$(get_random 7)
touch $FILE_NAME
chmod 000 $FILE_NAME
echo "File created with no permissions: $FILE_NAME"
ls -l $FILE_NAME
verbalize_permission() {
echo -n "$1's Permissions: "
permission=$2
if ((($permission & 4) != 0)); then
echo -n "r"
fi
if ((($permission & 2) != 0)); then
echo -n "w"
fi
if ((($permission & 1) != 0)); then
echo -n "x"
fi
echo
}
verbalize_permission "Owner" $owner
verbalize_permission "Group" $group
verbalize_permission "World" $world
echo "Try adding these permissions to the file: $FILE_NAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment