m (→Source) |
m (→UniqName) |
||
Line 13: | Line 13: | ||
The WedAug29194222CEST2012 string is a unique timestamp (within 1s of accuracy). | The WedAug29194222CEST2012 string is a unique timestamp (within 1s of accuracy). | ||
+ | |||
+ | == Locale == | ||
+ | |||
+ | This is working well and is useful only with English dates. Compare with <tt>jeu.19déc.2024232410CET</tt> using the | ||
+ | <pre> | ||
+ | laussy@azag:~$ echo $LC_TIME | ||
+ | fr_FR.UTF-8 | ||
+ | </pre> | ||
+ | so-called [https://en.wikipedia.org/wiki/Locale_(computer_software) locale]. This can be enforced from the script itself (adding the line <tt>LC_TIME=POSIX</tt> in the script, making it v1°0) or by setting it globally (e.g., adding the same <tt>LC_TIME=POSIX</tt> in <tt>~/.bashrc</tt>). | ||
+ | |||
+ | == Versions == | ||
+ | |||
+ | * 0°1: {{thisday|6|May|2005}}: the script without setting <tt>LC_TIME</tt>. | ||
+ | * 1°0: {{thisday|19|December|2024}}: enforcing <tt>LC_TIME</tt> (overriding default). | ||
== Source == | == Source == | ||
Line 18: | Line 32: | ||
<pre> | <pre> | ||
#!/bin/bash | #!/bin/bash | ||
− | + | #Unique Name generator based on date | |
− | # Unique Name generator based on date | + | #F.P. Laussy |
− | # F.P. Laussy | + | #Fri May 6 10:27:47 UTC 2005 v0°1 |
− | # Fri May | + | #Thu Dec 19 23:49:12 CET 2024 v1°0 |
+ | LC_TIME=POSIX | ||
date | tr -d ": " | tr -d "\n" | date | tr -d ": " | tr -d "\n" | ||
</pre> | </pre> |
Contents |
uniqname is an extremely simple script to generate a timestamp that can be used to define labels, filenames, variables, etc., which are unique if not invoked more than once per second.
A typical use is as a label in $\mathrm{\TeX}$ documents, or as a filename for temporary documents or quick notes (today, for instance, I sent a file called "WedAug29164757CEST2012.pdf" to co-workers).
By running it just now, I get:
uniqname WedAug29194222CEST2012
The WedAug29194222CEST2012 string is a unique timestamp (within 1s of accuracy).
This is working well and is useful only with English dates. Compare with jeu.19déc.2024232410CET using the
laussy@azag:~$ echo $LC_TIME fr_FR.UTF-8
so-called locale. This can be enforced from the script itself (adding the line LC_TIME=POSIX in the script, making it v1°0) or by setting it globally (e.g., adding the same LC_TIME=POSIX in ~/.bashrc).
#!/bin/bash #Unique Name generator based on date #F.P. Laussy #Fri May 6 10:27:47 UTC 2005 v0°1 #Thu Dec 19 23:49:12 CET 2024 v1°0 LC_TIME=POSIX date | tr -d ": " | tr -d "\n"