Bash
History
Ctrl+R will open the search history window.
You may now use Ctrl+R again to search for the previous match.
Edit current line in EDITOR
Ctrl-X, Ctrl-E: will open the current line in EDITOR.
Terminal title
echo -ne "\033]0;MY_NEW_TITLE\007"
Arrays
arr=(1 2 3)
echo ${arr[0]}
echo ${arr[@]}
echo ${arr[*]}
echo ...
copy=("${arr[@]}")
arr=(a b) # [ a, b ]
arr+=x # [ ax, b ]
arr+=(c) # [ ax, b, c ]
arr[3]=d # [ ax, b, c, d ]
arr[0]=a # [ a, b, c, d ]
arr+=(e f) # [ a, b, c, d, e, f ]
arr+=("d d") # [ a, b, c, d, e, f, "d d" ]
Cursor
Hide cursor
tput civis
Cursor movement
- Position the Cursor:
\033[
; H Or \033[ ; f puts the cursor at line L and column C. - Move the cursor up N lines:
\033[
A - Move the cursor down N lines:
\033[
B - Move the cursor forward N columns:
\033[
C -
Move the cursor backward N columns: \033[
D -
Clear the screen, move to (0,0): \033[2J
-
Erase to end of line: \033[K
-
Save cursor position: \033[s
- Restore cursor position: \033[u
Escape
escape1() { rul1='s:\:\\:g' rul2="s:':'\\'':g" /bin/echo -nE "$1" | sed "$rul1;$rul2;" }
escape() { # bashism: last part is to "cancel" empty, single argument #builtin printf ' %q' "$@" | cut -c2- | sed "s:^''$::"
# pure sh version for alpine and zimit and...
if [ "$*" != "" ]; then
while [ $# -gt 0 ]; do
/bin/echo -nE "'`escape1 "$1"`' "
shift
done
fi | sed 's: $::'
echo
}
TCP
exec 3<>/dev/tcp/192.168.1.10/80 echo "GET / HTTP/1.1" >&3 cat <&3