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/05/20 04:33] โ Humphrey Boa-Gart | tools:bash:customization [2025/01/04 03:40] (current) โ Humphrey Boa-Gart | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | {{wst> | ||
// This article is **Part 6** in a [[tools: | // This article is **Part 6** in a [[tools: | ||
====== Bash: Customization Basics ====== | ====== Bash: Customization Basics ====== | ||
- | ## Invocation Methods | + | The real power of bash is in its potential for limitless customization. When a bash shell is started, it goes down a list of predefined paths, looking for customization files. Depending on your operating system, it is likely that 99% of what you will need to do can be accomplished in **.bash_aliases**, |
- | #### Invoked as interactive login shell\n(ex: SSH, SU) | + | **.bashrc** and **.bash_profile** will take edits as well, but this is generally not advisable. Some operating systems have things mixed around, but by default most of them will have comments in the headings of these files explaining how they are arranged on your machine. |
- | 1. / | + | |
- | a. / | + | ===== Invocation Methods ===== |
- | 2. / | + | |
- | 3. ~/ | + | Depending on how bash is invoked and initialized, |
- | a. ~/.bashrc | + | |
- | 4. ~/ | + | ==== Invoked as interactive login shell ==== |
+ | |||
+ | (ex: SSH, SU) | ||
+ | |||
+ | - **/ | ||
+ | | ||
+ | - **/etc/bashrc** //(more global settings)// | ||
+ | - **~/ | ||
+ | - **~/.bashrc** //(more user configuration)// | ||
+ | - **~/.bash_aliases** //(user aliases file)// | ||
+ | - **~/ | ||
+ | |||
+ | ==== Invoked as interactive non-login shell ==== | ||
- | #### Invoked as interactive non-login shell | ||
(ex: within X window manager) | (ex: within X window manager) | ||
- | - ~/.bashrc | ||
- | #### Invoked non-interactively | + | - **~/ |
+ | - **~/ | ||
+ | |||
+ | ==== Invoked non-interactively | ||
(ex: scripts) | (ex: scripts) | ||
- | - Defined by BASH_ENV | ||
- | ## Basics | + | - Defined by '' |
- | ###### `$ echo $PATH` | + | ===== Aliases ===== |
- | See directories bash looks for scripts in. | + | |
- | ## Notes | + | 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 of typing you will do by setting **aliases**, |
- | * User specific functions should go in user\'s .bashrc | + | For example, lets look at the '' |
- | | + | |
- | ## Aliases | + | ls='ls -lhAF --color=auto' |
- | ###### `$ alias -p` | + | Aliases do not have to be permanent, either. To set that same alias to only work for the current shell session, you would run: |
- | See list of active aliases. | + | |
- | ###### `$ alias li=\'ls -li\'` | + | |
- | Create alias for li for current shell process only. | + | |
- | ###### `$ unalias` | + | To unset that alias, you would run: |
- | For unsetting aliases. | + | |
- | ## Environment Variables | + | $ unalias ls |
+ | |||
+ | You can also unset all aliases for the current shell session with: | ||
- | ### Getting Variable Info | + | $ unalias -a |
- | ###### `$ env` | + | To see a list of active aliases, run: |
- | See list of global variables. | + | |
- | ###### `$ printenv` | + | |
- | Same as above, but with less available option flags. | + | |
- | ###### `$ set` | + | ===== More Simple Tricks ===== |
- | See full list of global and local variables. | + | |
- | ###### `$ declare` | + | You can set all sorts of things up in your aliases file. The following are just a few tweaks you can make: |
- | Another long list of environment variables. | + | |
- | ###### `$ printenv HOME` | + | ==== Custom Hostnames ==== |
- | See value for global variable HOME. | + | |
- | ###### `$ echo $HOME` | + | You can tweak the prompt, aka the string that appears before |
- | Same as above. | + | |
- | ###### `$ ls $HOME` | + | If you want to restyle the prompt, you will need to set it to the **$PS1** variable. |
- | Use global | + | |
- | ### Setting Variables | + | PS1=' |
- | ###### `$ testvar=testvalue` | + | Here is a separate <wrap em>red version</ |
- | Set value of new local variable \' | + | |
- | ###### `$ testvar=\"A String Value\"` | + | PS1=' |
- | Same as above, but for strings. | + | |
- | ###### `$ testvar=$testvar: | + | Be careful setting |
- | Append more data to the end of existing | + | |
- | ###### `$ testvar=$(other | commands)` | + | //(See 'ANSI Escape Codes' at the bottom |
- | Assign variable | + | |
- | ###### `$ export testvar` | + | ==== Harden umask ==== |
- | Export a local variable to the global environment. | + | |
- | ###### `$ unset testvar` | + | 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/ |
- | Removes variable \' | + | |
- | ### Variable Arrays | + | umask 0077 |
- | ###### `$ vararray=(one two three four five)` | + | //(See [[tools: |
- | Define multiple values | + | |
- | ###### `$ echo ${vararray[2]}` | + | ===== Environment Variables ===== |
- | Echo column three from vararray. | + | |
- | ###### `$ echo ${vararray[*]}` | + | Just as in any programming language, bash uses **variables**. A variable in bash can contain a number, a character, or a string of characters. |
- | Echo entire array from vararray. | + | |
- | ###### `$ vararray[2]=whatever` | + | You have no need to declare a variable, as just assigning a value to its reference will create it. |
- | Change the value of column three in vararray. | + | |
- | ###### `$ unset vararry[2]` | + | ==== $PATH ==== |
- | Remove column 2 from vararray. Prior col 3 now new col 2. | + | |
- | ### Variable Notes | + | 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 above line shows that bash will look in your personal **~/ | ||
+ | |||
+ | To enable bash to run a custom application (such as a freshly downloaded [[tools: | ||
+ | |||
+ | $ ln -s / | ||
+ | |||
+ | With '' | ||
+ | |||
+ | You could also put the file or symlink in **/ | ||
+ | |||
+ | ==== Getting Variable Info ==== | ||
+ | |||
+ | See list of global variables: | ||
+ | |||
+ | $ env | ||
+ | |||
+ | Same as above, but with less available option flags: | ||
+ | |||
+ | $ printenv | ||
+ | |||
+ | See full list of global and local variables: | ||
+ | |||
+ | $ set | ||
+ | |||
+ | Another long list of environment variables: | ||
+ | |||
+ | $ declare | ||
+ | |||
+ | See value for global variable HOME: | ||
+ | |||
+ | $ printenv HOME | ||
+ | |||
+ | Same as above: | ||
+ | |||
+ | $ echo $HOME | ||
+ | |||
+ | Use global variable HOME as part of another command: | ||
+ | |||
+ | $ ls $HOME | ||
+ | |||
+ | ==== Setting Variables ==== | ||
+ | |||
+ | Set value of new local variable \' | ||
+ | |||
+ | $ testvar=testvalue | ||
+ | |||
+ | Same as above, but for strings: | ||
+ | |||
+ | $ testvar=\" | ||
+ | |||
+ | Append more data to the end of existing variable: | ||
+ | |||
+ | $ testvar=$testvar: | ||
+ | |||
+ | 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 ==== | ||
+ | |||
+ | Define multiple values for variable as array: | ||
+ | |||
+ | $ vararray=(one two three four five) | ||
+ | |||
+ | Echo column three from vararray: | ||
+ | |||
+ | $ echo ${vararray[2]} | ||
+ | |||
+ | Echo entire array from vararray: | ||
+ | |||
+ | $ echo ${vararray[*]} | ||
+ | |||
+ | 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 ==== | ||
* Get value of variables with `$`, but don\'t use `$` when assigning them. | * Get value of variables with `$`, but don\'t use `$` when assigning them. | ||
Line 112: | Line 199: | ||
* Export and unset, when used in a child shell, will not affect the parent shell. | * Export and unset, when used in a child shell, will not affect the parent shell. | ||
* 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 | | ||
+ | |||
+ | |||
---- | ---- | ||
+ | * Previous Page: [[tools: | ||
* [[tools: | * [[tools: | ||
+ | |||
+ | |||
+ | {{wst> |
tools/bash/customization.1716179628.txt.gz ยท Last modified: 2024/08/06 05:54 (external edit)
Find this page online at: https://bestpoint.institute/tools/bash/customization
Find this page online at: https://bestpoint.institute/tools/bash/customization