Bash Shell: Difference between revisions
→Test: Moved to Bash Scripting |
|||
| Line 93: | Line 93: | ||
{| class="wikitable" | {| class="wikitable" | ||
| 2>&1 | | {{code|2>&1}} | ||
| STDERR to STDOUT | | STDERR to STDOUT | ||
|- | |- | ||
| &> | | {{code|&>}} | ||
| Redirect both STDERR and STDOUT | | Redirect both STDERR and STDOUT | ||
|} | |} | ||
If you wish to redirect both STDERR and STDOUT, you need to redirect STDOUT and then STDERR like so: | |||
{{highlight|lang=terminal|code= | |||
# ./some-program > /dev/null 2>&1 | |||
}} | |||
== Prompt == | == Prompt == | ||
Revision as of 20:47, 29 July 2019
Bash, short for the Bourne Again Shell, is a popular interactive shell for Unix based systems and is the default for many distributions.
This article will go over some tips and tricks on using Bash interactively. For more information on scripting in Bash, see Bash Scripting.
User Interactive Keys
Here are some keyboard shortcuts when using the interactive shell. These also work under zsh.
| CTRL + a | Go to start of line (Home key) |
| CTRL + e | Go to end of line (End key) |
| CTRL + b | Back one character (left arrow) |
| CTRL + f | Forward one character (right arrow) |
| ALT + b | Back one word (like in vi 'b') |
| ALT + f | Forward one word (like in vi 'w') |
Editing
| CTRL + d | Delete character under cursor (Delete key) |
| CTRL + h | Delete character before cursor (backspace) |
| ALT - U | Converts to uppercase the word ahead of the cursor |
| ALT - L | Converts to lowercase the word ahead of the cursor |
| CTRL + w | Cuts word before cursor to clipboard |
| CTRL + u | Cuts entire line to clipboard |
| CTRL + y | Pastes the contents of the clipboard (un yank) |
| CTRL + - | Undo a change |
| ALT + r | Restores line from history |
Previous Command / Arguments
| !! | Run last command |
| !xyz | Run last command starting with xyz |
| !* | All arguments of the previous command |
| !$ / ALT + . | Last argument of the previous command |
| !!:p / !xyz:p / !*:p / !$:p | Prints instead of executes the command/arguments |
| ^abc^xyz | Runs the previous command with 'abc' replaced with 'xyz' |
Others
| CTRL + l | Clears screen |
| CTRL + q | Stops flow / pauses output |
| CTRL + s | Resumes flow / unpauses output |
Redirection
2>&1
|
STDERR to STDOUT |
&>
|
Redirect both STDERR and STDOUT |
If you wish to redirect both STDERR and STDOUT, you need to redirect STDOUT and then STDERR like so:
# ./some-program > /dev/null 2>&1
Prompt
The shell prompt can be set by changing the PS1 environment variable. This is my colored prompt:
<phorkie>https://phorkie.leo.home.steamr.com/12/embed</phorkie>