Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snippets #20

Open
nntrn opened this issue Mar 13, 2023 · 8 comments
Open

Snippets #20

nntrn opened this issue Mar 13, 2023 · 8 comments

Comments

@nntrn
Copy link
Owner

nntrn commented Mar 13, 2023

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

github-actions bot pushed a commit that referenced this issue Mar 13, 2023
@nntrn
Copy link
Owner Author

nntrn commented Mar 15, 2023

$ 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|!^"'
                      `!^"'

github-actions bot pushed a commit that referenced this issue Mar 15, 2023
@nntrn
Copy link
Owner Author

nntrn commented Mar 20, 2023

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/}

github-actions bot pushed a commit that referenced this issue Mar 20, 2023
@nntrn
Copy link
Owner Author

nntrn commented Jun 28, 2023

$ a=1
$ result=$[$a + 3]
$ echo $result
4

https://linuxreviews.org/Bourne_Shell_Reference

@nntrn
Copy link
Owner Author

nntrn commented Jan 3, 2024

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.

@nntrn
Copy link
Owner Author

nntrn commented Mar 21, 2024

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' \)

@nntrn
Copy link
Owner Author

nntrn commented Mar 28, 2024

Security

Terminate SSH Agent on Logout

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

@nntrn
Copy link
Owner Author

nntrn commented May 24, 2024

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

@nntrn
Copy link
Owner Author

nntrn commented May 25, 2024

Count words using tr

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant