Difference between revisions of "Bash Shell"

From 6bit.ch wiki
Jump to navigation Jump to search
(Created page with "= CTRL Hotkeys = CTRL + a</br> move to beginning CTRL + d</br> escape current shell or delete character under cursor CTRL + e</br> move to end CTRL + k</br> delete all from cursor to end CTRL + l</br> clear CTRL + n</br> down arrow CTRL + p</br> up arrow CTRL + q</br> resume output CTRL + r</br> backward search CTRL + s</br> stop output CTRL + t</br> switch character before cursor with cursor, ESC + t switches two words before the cursor CTRL + u</br> cut lin...")
 
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
= CTRL Hotkeys =
== Hotkeys ==


CTRL + a</br>
=== Navigation ===
move to beginning


CTRL + d</br>
<code>CTRL + a</code> move to beginning</br>
escape current shell or delete character under cursor
<code>CTRL + e</code> move to end</br>


CTRL + e</br>
<code>ALT + f</code> move forward by one word</br>
move to end
<code>ALT + b</code> move backward by one word</br>


CTRL + k</br>
<code>CTRL + n</code> down arrow</br>
delete all from cursor to end
<code>CTRL + p</code> up arrow</br>


CTRL + l</br>
=== Text Control ===
clear
<code>CTRL + k</code> cut after cursor</br>
<code>CTRL + l</code> clear</br>
<code>CTRL + u</code> cut before cursor</br>
<code>CTRL + w</code> cut word before cursor</br>
<code>CTRL + y</code> paste</br>
<code>CTRL + _</code> undo typing</br>
<code>ALT + r</code> undo changes made to command from history</br>


CTRL + n</br>
=== Misc ===
down arrow


CTRL + p</br>
<code>CTRL + r</code> backward search</br>
up arrow
<code>CTRL + g</code> leave search without running a command</br>
<code>CTRL + j</code> copy current matched command to cli without running it</br>
<code>CTRL + s</code> stop output</br>
<code>CTRL + q</code> resume output</br>
<code>CTRL + d</code> escape current shell or delete character under cursor</br>
<code>CTRL + t</code> switch character before cursor with cursor</br>
</br>
<code>$_</code> repeat last argument. Risky in scripts, best use case after &&.


CTRL + q</br>
== Functions ==
resume output


CTRL + r</br>
Single Parenthesis <code>( ... )</code> is creating a subshell for nested commands</br>
backward search
Double Parenthesis <code>(( ... ))</code> is for arithmetic operation</br>
Single Square Bracket <code>[ ... ]</code> is the syntax for the POSIX ''test''</br>
Double Square Brackets <code>&#91;&#91; ... &#93;&#93;</code> is the syntax for conditional expressions (similar to ''test'' but more powerful)</br>


CTRL + s</br>
Single Ampersand <code>command1 & command2</code> run command1 in the background</br>
stop output
Double Ampersand <code>command1 && command2</code> run command2 only if command1 succeeded</br>
Single Pipe <code>command1 | command2</code> use output of command1 as input for command2</br>
Double Pipe <code>command1 || command2</code> run command2 only if command1 failed</br>


CTRL + t</br>
switch character before cursor with cursor, ESC + t switches two words before the cursor


CTRL + u</br>
=== Change to the directory of the script ===
cut line
<code>cd "$(dirname "$(readlink -f "$0")")"</code></br>
 
1. ''readlink -f "$0"'' determines the path of the current script ($0)</br>
CTRL + _</br>
2. ''dirname'' converts the path of the script to its directory</br>
undo typing
3. ''cd'' changes the working directory to the directory it receives from ''dirname''</br>
 
CTRL + w</br>
cut word
 
CTRL + y</br>
paste
 
CTRL + x + bspace</br>
delte all from beginning to cursor
 
CTRL + x + CTRL + e</br>
lauch editor ($EDITOR)

Latest revision as of 17:28, 18 December 2025

Hotkeys

Navigation

CTRL + a move to beginning
CTRL + e move to end

ALT + f move forward by one word
ALT + b move backward by one word

CTRL + n down arrow
CTRL + p up arrow

Text Control

CTRL + k cut after cursor
CTRL + l clear
CTRL + u cut before cursor
CTRL + w cut word before cursor
CTRL + y paste
CTRL + _ undo typing
ALT + r undo changes made to command from history

Misc

CTRL + r backward search
CTRL + g leave search without running a command
CTRL + j copy current matched command to cli without running it
CTRL + s stop output
CTRL + q resume output
CTRL + d escape current shell or delete character under cursor
CTRL + t switch character before cursor with cursor

$_ repeat last argument. Risky in scripts, best use case after &&.

Functions

Single Parenthesis ( ... ) is creating a subshell for nested commands
Double Parenthesis (( ... )) is for arithmetic operation
Single Square Bracket [ ... ] is the syntax for the POSIX test
Double Square Brackets [[ ... ]] is the syntax for conditional expressions (similar to test but more powerful)

Single Ampersand command1 & command2 run command1 in the background
Double Ampersand command1 && command2 run command2 only if command1 succeeded
Single Pipe command1 | command2 use output of command1 as input for command2
Double Pipe command1 || command2 run command2 only if command1 failed


Change to the directory of the script

cd "$(dirname "$(readlink -f "$0")")"
1. readlink -f "$0" determines the path of the current script ($0)
2. dirname converts the path of the script to its directory
3. cd changes the working directory to the directory it receives from dirname