Snippets

https://github.com/nntrn/save/issues/20

Created on Last updated on


Prompt Statements Variables

  • PS1 – Default interactive prompt (this is the variable most often customized)

  • PS2 – Continuation interactive prompt (when a long command is broken up with \ at the end of the line) default=">"

  • PS3 – Prompt used by “select” loop inside a shell script

  • PS4 – Prompt used when a shell script is executed in debug mode (set -x will turn this on) default ="++"
    PS4='+${BASH_SOURCE[0]##*/}($LINENO)/${FUNCNAME[0]}> '

  • PROMPT_COMMAND - If this variable is set and has a non-null value, then it will be executed just before the PS1 variable.

Read more: How-to: Setup Prompt Statement variables

$ base64 -d <<<"H4sIAAAAAAAAA9WUPWvDMBCGd/0Knxct6o3BlikpGTqHYlq6qIopAUNqQ0m2/Pjoq/qyE6fQpTdaz/PK0p1dFLOFjJ3Gz2pTdeOJMSTZKtrVrF62z+36AD2PePb4lXMGg3NSQQBE5NC+OjAgAEKUJVXIVEAjrTPO17yAqJ/PHv9/Ck/DcPwe/mgHuSiwVCiwuS584AOA77QZnzc9C10uBND0klMC7+n4KEUDHCMS+nG/qjY+kajj5lqIjWg3jJybExNzS7m42/XHCe/KXRVx15upE6PhIErZ/IixmsjZLlxQqifcZvhL7dXLjUhCp1REbqbVmJMryQbYFoz6c41CbrqhOhsi9WtvBSXJ0CzJkxSSTN2yFwX4EZROXZZ01fW+hWh8pXbhHuusmkiTX6KkBUD9O8d4MN3wOq35+i7OkrcJzai1C9fflmABBgAA" | gunzip
                       .,,uod8B8bou,,.
              ..,uod8BBBBBBBBBBBBBBBBRPFT?l!i:.
         ,=m8BBBBBBBBBBBBBBBRPFT?!||||||||||||||
         !...:!TVBBBRPFT||||||||||!!^^""'   ||||
         !.......:!?|||||!!^^""'            ||||
         !.........||||                     ||||
         !.........||||                     ||||
         !.........||||                     ||||
         !.........||||                     ||||
         !.........||||       @nntrn        ||||
         !.........||||                     ||||
         `.........||||                    ,||||
          .;.......||||               _.-!!|||||
   .,uodWBBBBb.....||||       _.-!!|||||||||!:'
!YBBBBBBBBBBBBBBb..!|||:..-!!|||||||!iof68BBBBBb....
!..YBBBBBBBBBBBBBBb!!||||||||!iof68BBBBBBRPFT?!::   `.
!....YBBBBBBBBBBBBBBbaaitf68BBBBBBRPFT?!:::::::::     `.
!......YBBBBBBBBBBBBBBBBBBBRPFT?!::::::;:!^"`;:::       `.
!........YBBBBBBBBBBRPFT?!::::::::::^''...::::::;         iBBbo.
`..........YBRPFT?!::::::::::::::::::::::::;iof68bo.      WBBBBbo.
  `..........:::::::::::::::::::::::;iof688888888888b.     `YBBBP^'
    `........::::::::::::::::;iof688888888888888888888b.     `
      `......:::::::::;iof688888888888888888888888888888b.
        `....:::;iof688888888888888888888888888888888899fT!
          `..::!8888888888888888888888888888888899fT|!^"'
            `' !!988888888888888888888888899fT|!^"'
                `!!8888888888888888899fT|!^"'
                  `!988888888899fT|!^"'
                    `!9899fT|!^"'
                      `!^"'

Publish step

    - name: Publish
      run: |
        git config --global user.email "actions@github.com"
        git config --global user.name "Actions"
        git add actions-cheat-sheet.*
        git commit -m 'AsciiDoctor-PDF build from Actions'
        git push --force origin HEAD:${GITHUB_REF#refs/heads/}
$ a=1
$ result=$[$a + 3]
$ echo $result
4

https://linuxreviews.org/Bourne_Shell_Reference

Also, don't forget to set PS4 to something useful like the following. In most cases set -x is useless without it.

export PS4='${BASH_SOURCE[0]}:$LINENO '

This will cause the script name and line numbers to be printed as well.

find

Traversing the filesystem just once - for 2 different actions

  • Traverse the filesystem just once, listing set-user-ID files and directories into /root/suid.txt
  • and large files into /root/big.txt.
find / \
    \( -perm -4000 -fprintf /root/suid.txt '%#m %u %p\n' \) , \
    \( -size +100M -fprintf /root/big.txt '%-10s %p\n' \)

Security

Terminate SSH Agent on Logout

# ~/.bash_profile
trap 'test -n "$SSH_AGENT_PID" && eval `/usr/bin/ssh-agent -k`' 0

encrypt files with gpg

echo 'helloooooo' >password.txt
SECRET_PASSPHRASE=hello

# encrypt file (creates password.txt.gpg)
gpg --symmetric --cipher-algo AES256 password.txt

# decrypt
gpg --quiet --batch --yes --decrypt --passphrase="$SECRET_PASSPHRASE" --output /tmp/password.txt password.txt.gpg

https://docs.github.com/en/actions/security-guides/encrypted-secrets

Count words using tr

tr '[:upper:]' '[:lower:]' < whats.gnu | 
  tr -cd '[:alnum:]_ \n' | 
  tr -s ' ' '\n' | 
  sort | 
  uniq -c