Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacement for chmod --reference on OS X?

I'm trying to port some jenkins bash scripts from Ubuntu to OS X. The linux (and I think it is originally GNU) chmod has a --reference option that allows copying the mode from a reference file. I am looking for the equivalent code for OS X, preferably without installing extra packages. Even better would be a cross-platform solution.

The concrete snippet:

# expand all the templates
find "$OUTPUT_PATH" -name "*.template" | while read FILE ; do
    sed \
        -e "s/%{NAME}/$OPTION_NAME/g" \
        -e "s/%{TITLE}/$OPTION_TITLE/g" \
        -e "s/%{VERSION}/$OPTION_VERSION/g" \
        -e "s/%{WHEN}/$OPTION_WHEN/g" \
            "$FILE" > "${FILE%.*}"
    chmod --reference="$FILE" "${FILE%.*}"
    rm -f "$FILE"
done

[edit] The combination of stat -r with saving the file mode is the right combination, stat -c doesn't exist on OS X

like image 621
Stephan Eggermont Avatar asked Apr 22 '11 08:04

Stephan Eggermont


1 Answers

Copy the file first and only then overwrite with a shell redirection. This should preserve the original permissions.

like image 114
Adam Byrtek Avatar answered Nov 15 '22 21:11

Adam Byrtek