ao-mud is a spellbook of well-commented atomic bash scripts that each do one thing. we are building semantic building blocks for an autonomously-evolving digital spellcasting language.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.4 KiB

#!/bin/sh
# This spell enchants the specified file with the given attribute and value.
# If the attribute already exists, it is overwritten.
# If the file or attribute does not exist, it raises an error.
# Check that the correct number of arguments was provided
if [ $# -lt 3 ] | [ $# -gt 4 ]; then
echo "Error: This spell requires three or four arguments: a file path, an attribute name, and a value."
exit 1
fi
# Set the file path, attribute name, and attribute value variables
file=$1
attribute=$2
value=$3
# Check that the file exists
if [ ! -f "$file" ]; then
echo "Error: The file does not exist."
exit 1
fi
# Define a function to set the attribute value using the available commands
set_attribute_value() {
# Try to set the attribute using the 'attr' command
attr -s "$1" -V "$2" "$3" 2>&1 >/dev/null ||
# If the 'attr' command is not available, try using the 'xattr' command
xattr -w "$1" "$2" "$3" 2>&1 > /dev/null ||
# If the 'xattr' command is not available, try using the 'setfattr' command
setfattr -n "$1" -v "$2" "$3" 2>&1 > /dev/null ||
# If none of the commands are available, raise an error
(
echo "Error: This spell requires the 'attr', 'xattr', or 'setfattr' command to be installed."
exit 1
)
}
# Set the attribute value using the set_attribute_value function
set_attribute_value "$attribute" "$value" "$file"
echo "The file has been enchanted with the attribute '$attribute' and value '$value'."