tivasyk

simple output templates with bash

Jul 17th, 2019
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.54 KB | None | 0 0
  1. #!/bin/bash
  2. # tivasyk <[email protected]>
  3.  
  4. # Template
  5. TEMPLATE="<YELLOW><HOSTNAME><NORMAL><TAB>| <DATE>, <TIME>"
  6.  
  7. PRINT="${TEMPLATE}"
  8. # Substitute colors
  9. PRINT="${PRINT//<YELLOW>/$(tput setaf 3)}"
  10. PRINT="${PRINT//<NORMAL>/$(tput sgr0)}"
  11. # Substitute formatting
  12. TAB=$(echo -e '\t')
  13. PRINT="${PRINT//<TAB>/${TAB}}"
  14. # Substitute tags
  15. PRINT="${PRINT//<HOSTNAME>/$(hostname)}"
  16. PRINT="${PRINT//<DATE>/$(date +'%Y-%m-%d')}"
  17. PRINT="${PRINT//<TIME>/$(date +'%H:%M')}"
  18.  
  19. printf "Template: %s\n" "${TEMPLATE}"
  20. printf "Substit.: %s\n" "${PRINT}"
Advertisement
Add Comment
Please, Sign In to add comment