In trying to read all the values of the extended attributes on a single file, if I do
xattr -l <filename> | while read ATTR; do
xattr -p $ATTR <filename>
done
I get what I expect. But if I try to do multiple files with
for FILE in *; do
echo "=== $FILE ==="
xattr -l $FILE | while read ATTR; do
xattr -p $ATTR $FILE
done
done
for some files I get only the filename (no xattr, I suppose);
for some files I get
=== 154128428159.JPEG ===
xattr: [Errno 22] Invalid argument: '154128428159.JPEG'
xattr: 154128428159.JPEG: No such xattr: com.apple.macl:
xattr: [Errno 22] Invalid argument: '154128428159.JPEG'
Not enough arguments for option -p. Expected at least 2 but got 1
and for other files,
xattr: [Errno 22] Invalid argument: 'record-image_-7.jpg'
xattr: record-image_-7.jpg: No such xattr: com.apple.macl:
xattr: [Errno 63] File name too long: 'record-image_-7.jpg'
I tried putting unset ATTR
or ATTR=""
in the outer loop, but got the same results.
This is with either zsh or bash on macOS 13.5.2
xattr $FILE
, without any options. With the-l
option, it will include the attribute values, which may include multiple lines and even empty lines.-l
lists the names of the attributes. But it only allows one attribute at a time, hence looping on the names.