tools:bash:customization
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tools:bash:customization [2024/06/04 01:05] – Humphrey Boa-Gart | tools:bash:customization [2025/09/30 22:44] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | {{wst> | ||
| // This article is **Part 6** in a [[tools: | // This article is **Part 6** in a [[tools: | ||
| Line 37: | Line 36: | ||
| - Defined by '' | - Defined by '' | ||
| - | ===== $PATH ===== | + | ===== Aliases |
| - | The $PATH variable specifies the directories that bash will look for executable files. (So you can type '' | + | As you start to use bash more often, you will find yourself using specific combinations of commands and flags to accomplish basic tasks. You can drastically cut the amount |
| - | | + | For example, lets look at the '' |
| + | |||
| + | ls='ls -lhAF --color=auto' | ||
| + | |||
| + | Aliases do not have to be permanent, either. To set that same alias to only work for the current shell session, you would run: | ||
| + | |||
| + | | ||
| + | |||
| + | To unset that alias, you would run: | ||
| + | |||
| + | | ||
| | | ||
| + | You can also unset all aliases for the current shell session with: | ||
| + | |||
| + | $ unalias -a | ||
| + | |||
| + | To see a list of active aliases, run: | ||
| + | |||
| + | $ alias -p | ||
| + | |||
| + | ===== More Simple Tricks ===== | ||
| + | |||
| + | You can set all sorts of things up in your aliases file. The following are just a few tweaks you can make: | ||
| + | |||
| + | ==== Custom Hostnames ==== | ||
| + | |||
| + | You can tweak the prompt, aka the string that appears before $ in your terminal. (Usually something like **[user@host]$**) | ||
| + | |||
| + | If you want to restyle the prompt, you will need to set it to the **$PS1** variable. Here is one example with custom green and blue color codes, which you can copy/paste to your aliases file and use right away: | ||
| + | |||
| + | PS1=' | ||
| + | |||
| + | Here is a separate <wrap em>red version</ | ||
| + | |||
| + | PS1=' | ||
| + | |||
| + | Be careful setting the **$PS1** variable, as you can very easily make your shell unusable if you set it the wrong way! | ||
| + | |||
| + | //(See 'ANSI Escape Codes' at the bottom of this page for more color options.)// | ||
| + | |||
| + | ==== Harden umask ==== | ||
| + | |||
| + | By default your **umask** is probably set up to give read access to things that do not need it by default. To make it so all new files/ | ||
| + | |||
| + | umask 0077 | ||
| + | |||
| + | //(See [[tools: | ||
| + | |||
| + | ===== Environment Variables ===== | ||
| + | |||
| + | Just as in any programming language, bash uses **variables**. A variable in bash can contain a number, a character, or a string of characters. | ||
| + | |||
| + | You have no need to declare a variable, as just assigning a value to its reference will create it. | ||
| + | |||
| + | ==== $PATH ==== | ||
| + | |||
| + | The most important variable you will deal with, is the **$PATH** variable, which specifies the directories that bash will look for executable files. (So you can type '' | ||
| + | |||
| + | $ echo $PATH | ||
| + | |||
| This will output something like: | This will output something like: | ||
| / | / | ||
| | | ||
| - | To enable | + | This above line shows that bash will look in your personal |
| - | $ ln -s path/to/the.appimage | + | To enable bash to run a custom application (such as a freshly downloaded [[tools: |
| - | + | ||
| - | With '' | + | |
| - | ===== Aliases ===== | + | $ ln -s / |
| - | ###### `$ alias -p` | + | With '' |
| - | See list of active aliases. | + | |
| - | ###### `$ alias li=\' | + | You could also put the file or symlink in **/ |
| - | Create alias for li for current shell process only. | + | |
| - | ###### `$ unalias` | + | ==== Getting Variable Info ==== |
| - | For unsetting aliases. | + | |
| - | ===== Environment Variables ===== | + | See list of global variables: |
| - | ==== Getting Variable Info ==== | + | $ env |
| + | |||
| + | Same as above, but with less available option flags: | ||
| - | ###### `$ env` | + | |
| - | See list of global variables. | + | |
| - | ###### `$ printenv` | + | See full list of global and local variables: |
| - | Same as above, but with less available option flags. | + | |
| - | ###### `$ set` | + | |
| - | See full list of global and local variables. | + | |
| - | ###### `$ declare` | + | Another long list of environment variables: |
| - | Another long list of environment variables. | + | |
| - | ###### `$ printenv HOME` | + | |
| - | See value for global variable HOME. | + | |
| - | ###### `$ echo $HOME` | + | See value for global variable |
| - | Same as above. | + | |
| - | ###### `$ ls $HOME` | + | |
| - | Use global variable HOME as part of another command. | + | |
| + | Same as above: | ||
| + | |||
| + | $ echo $HOME | ||
| + | |||
| + | Use global variable HOME as part of another command: | ||
| + | |||
| + | $ ls $HOME | ||
| ==== Setting Variables ==== | ==== Setting Variables ==== | ||
| - | ###### `$ testvar=testvalue` | + | Set value of new local variable \' |
| - | Set value of new local variable \' | + | |
| - | ###### `$ testvar=\"A String Value\" | + | |
| - | Same as above, but for strings. | + | |
| - | ###### `$ testvar=$testvar:moredata` | + | Same as above, but for strings: |
| - | Append more data to the end of existing variable. | + | |
| - | ###### `$ testvar=$(other | commands)` | + | |
| - | Assign variable the result of set of commands. | + | |
| - | ###### `$ export testvar` | + | Append more data to the end of existing variable: |
| - | Export a local variable | + | |
| - | ###### `$ unset testvar` | + | |
| - | Removes variable \' | + | |
| + | Assign variable the result of set of commands: | ||
| + | |||
| + | $ testvar=$(other | commands) | ||
| + | |||
| + | Export a local variable to the global environment: | ||
| + | |||
| + | $ export testvar | ||
| + | |||
| + | Removes variable \' | ||
| + | |||
| + | $ unset testvar | ||
| ==== Variable Arrays ==== | ==== Variable Arrays ==== | ||
| - | ###### `$ vararray=(one two three four five)` | + | Define multiple values for variable as array: |
| - | Define multiple values for variable as array. | + | |
| - | ###### `$ echo ${vararray[2]}` | + | |
| - | Echo column | + | |
| - | ###### `$ echo ${vararray[*]}` | + | Echo column three from vararray: |
| - | Echo entire array from vararray. | + | |
| - | ###### `$ vararray[2]=whatever` | + | |
| - | Change the value of column three in vararray. | + | |
| - | ###### `$ unset vararry[2]` | + | Echo entire array from vararray: |
| - | Remove column 2 from vararray. Prior col 3 now new col 2. | + | |
| + | | ||
| + | |||
| + | Change the value of column three in vararray: | ||
| + | |||
| + | $ vararray[2]=whatever | ||
| + | |||
| + | Remove column 2 from vararray. Prior col 3 now new col 2: | ||
| + | |||
| + | $ unset vararry[2] | ||
| ==== Variable Notes ==== | ==== Variable Notes ==== | ||
| Line 134: | Line 200: | ||
| * Variable arrays start with an index value of zero, not one. | * Variable arrays start with an index value of zero, not one. | ||
| - | ---- | + | ===== ANSI Escape Codes ===== |
| + | |||
| + | When you set your custom hostname earlier in this article, you may have noticed the **\033[..m]** or **\033[..; | ||
| + | |||
| + | ==== Color Codes ==== | ||
| + | |||
| + | ^ Color ^ Foreground Code ^ Background Code ^ | ||
| + | | Black | 30 | 40 | | ||
| + | | Red | 31 | 41 | | ||
| + | | Green | 32 | 42 | | ||
| + | | Yellow | ||
| + | | Blue | 34 | 44 | | ||
| + | | Magenta | ||
| + | | Cyan | 36 | 46 | | ||
| + | | Light Gray | 37 | 47 | | ||
| + | | Gray | 90 | 100 | | ||
| + | | Light Red | 91 | 101 | | ||
| + | | Light Green | 92 | 102 | | ||
| + | | Light Yellow | 93 | 103 | | ||
| + | | Light Blue | 94 | 104 | | ||
| + | | Light Magenta | 95 | 105 | | ||
| + | | Light Cyan | 96 | 106 | | ||
| + | | White | 97 | 107 | | ||
| + | |||
| + | ==== Other Codes ==== | ||
| + | |||
| + | ^ Code ^ Description | ||
| + | | 00 | Reset/ | ||
| + | | 01 | Bold text | | ||
| + | | 02 | Faint text | | ||
| + | | 03 | Italics | ||
| + | | 04 | Underlined text | | ||
| + | |||
| + | |||
| + | |||
| + | {{wst> | ||
| - | * [[tools: | ||
tools/bash/customization.1717463110.txt.gz · Last modified: (external edit)
Find this page online at: https://bestpoint.institute/tools/bash/customization
Find this page online at: https://bestpoint.institute/tools/bash/customization