Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Typo in function date #133

Open
MegaV0lt opened this issue Jan 10, 2023 · 1 comment
Open

Typo in function date #133

MegaV0lt opened this issue Jan 10, 2023 · 1 comment

Comments

@MegaV0lt
Copy link

I think there is an extra '\' in the printf command

date() {
    # Usage: date "format"
    # See: 'man strftime' for format.
    printf "%($1)T\\n" "-1"
}
@gooey
Copy link

gooey commented Jan 10, 2023

@MegaV0lt since the printf format string uses double quotes instead of single-quotes, parameter expansion and command substitutions will be applied, as well as backslash escapes - twice. Hence the \\n is reduced to \n when you declare the function and printf ... prints a \n.

Since someone may go ahead and stupidly copy-paste this in like

cat > my_source-able_file.sh <<EOF
date() {
    # Usage: date "format"
    # See: 'man strftime' for format.
    printf "%($1)T\\n" "-1"
}
EOF

... they'll still get a working function even if they make that mistake.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants