Skip to content
Jasper Zanjani edited this page Aug 26, 2020 · 1 revision

NVMe

Shells

bash

  • getopt and argp_parse reorder the elements of argv by default, but this behavior can be suppressed by setting the _POSIX_OPTION_ORDER environment variable

Terminal prompt

ANSI/VT100 terminals and emulators can display colors and formatted texts by using escape sequences ( escape character followed by format code, terminated by "m").
Three escape characters:

  • \e
  • \033
  • \x1B

Syntax

Event designator Effect
!^ first argument from previous command
!$ last argument from previous command
^string repeat last command, deleting the first instance of {string}
^string^substitute repeat last command, substituting the first instance of {string} with {substitute} (CLKF)
!!:n {n}th argument from previous command
!#:n {n}th word of current command
Syntax Effect
$((...)) arithmetic expansion
[...] alias for test
$(...) command substitution
${...} variable substitution
${var:start:size} variable slicing
filename{,.new} brace expansion makes multiple arguments from a single one

Content of all loops is bracketed by do and done: for i in ... do ...; done; and for ((i=0; i<N; i++)); do cmd; done;

  • for i in {01..07}; do cmd; done;
  • for i in {000..100}; do cmd; done;
  • for i in 1 2 3 4 5; do cmd; done;
Number bases Description
r#n general format for interpreting number as having base (radix)
2#1111001110011010 binary
0x32 hex numbers
032 octal
32#@_ base-32: a range of ASCII characters can be used to define numbers with bases up to 64: 10 digits, 26 lowercase characters, 26 uppercase characters, '@', and '_'
Command sequence syntax Effect
; run commands synchnonously
& run commands asynchronously
&& logical AND; run next command synchronously only if first command succeeds
`

Variables

[3]

Elvish shell

if/else

~> if $true { echo good } else { echo bad }

for loop iterating over an array

~> for x [lorem ipsum] {
     echo $x.pdf
   }

try/catch block and raising an error

~> try {
     fail 'bad error'
   } except e {
     echo error $e
   } else {
     echo ok
   }

Fish

Fish color variables

  • fish_color_normal
  • fish_color_command
  • fish_color_quote
  • fish_color_redirection

Sources

  1. gnu.org
  2. putorius.net
  3. "Using Variables in bash" opensource.com: 2019/08/26.
  4. ItsFOSS

Clone this wiki locally