linux - bash: meaningful unique id generation -


i using following command generate unique id shell script. want capture output in variable without using intermediate file on hard disk.

    echo `dmidecode –t 4 -s system-uuid`-$$-$bash_subshell-$bashpid-`date '+%y%m%d_%h%m_%s_%n'` | tr '-' '_'     xxb3a1xx_81xx_4xx2_axx4_xxxx62820bf_24115_0_8550_201709xx_1446_46_385924883 

i can use backquote or $() construct doing changes value of $bash_subshell , dilutes value of unique id.

any solution welcome not use hard disk , not change $bash_subshell value while capturing output in variable.

note: result in example partly obscured x

use printf , save variables in format string:

format="%s-$$-$bash_subshell-$bashpid-%s" uuid=$(printf "$format" $(dmidecode –t 4 -s system-uuid) $(date '+%y%m%d_%h%m_%s_%n') | tr - _) 

then:

$ echo "$uuid" xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx_11764_0_11764_20170912_1906_42_765827138 $ echo `dmidecode –t 4 -s system-uuid`-$$-$bash_subshell-$bashpid-`date '+%y%m%d_%h%m_%s_%n'` | tr '-' '_' xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx_11764_0_11865_20170912_1909_28_405748643 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -