Home > Net >  Why date ' %s%N' not working on mac terminal?
Why date ' %s%N' not working on mac terminal?

Time:06-10

I am working on bash scripts on both linux and mac.

I run this command on remote server with linux OS and it just work perfect.

CURRENT_TIME=$(date ' %s%N') 
echo "$CURRENT_TIME"

However, when I run the same command on mac terminal, it shows this error:

1654778186N: value too great for base (error token is "1654778186N")

It look like mac terminal did not recognized the '%N'. What should I do to fix the issue on mac terminal?

CodePudding user response:

%N is a GNU extension to the POSIX standard, as clarified in GNU's own documentation: https://www.gnu.org/software/coreutils/manual/html_node/Time-conversion-specifiers.html

The POSIX version of date, doesn't include %N: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/date.html

If I recall correctly, POSIX-certified systems (and macOS is certified) cannot add custom extensions to POSIX tools to guarantee portability across systems.

  • Related