From d60811a78a56fcfc39d573d626c097301ef6585f Mon Sep 17 00:00:00 2001 From: garhve Date: Fri, 2 Dec 2022 22:50:35 +0800 Subject: blog transfer --- posts/1/index.html | 4 +- posts/4/index.html | 24 +- posts/5/index.html | 1450 ++++++++++++++++++++++++++++++++++++++++++++++++++++ posts/6/index.html | 359 +++++++++++++ posts/7/index.html | 164 ++++++ posts/index.html | 43 +- posts/index.xml | 38 +- 7 files changed, 2064 insertions(+), 18 deletions(-) create mode 100644 posts/5/index.html create mode 100644 posts/6/index.html create mode 100644 posts/7/index.html (limited to 'posts') diff --git a/posts/1/index.html b/posts/1/index.html index d8f4fef..b6a47de 100644 --- a/posts/1/index.html +++ b/posts/1/index.html @@ -152,8 +152,8 @@ Due to personal interest, I didn’t choose frame to base my website. I listen 443 ssl http2; listen [::]:443 ssl http2; - server_name garhve.com - include /path_to_cert_file; + server_name garhve.com; + include /path_to_cert_file; #location to real content } # this block is where we hold web content. diff --git a/posts/4/index.html b/posts/4/index.html index 2e314e2..b9d798a 100644 --- a/posts/4/index.html +++ b/posts/4/index.html @@ -58,6 +58,17 @@ User space: For applications to run in unprivileged user mode Kernel space: For + + @@ -146,19 +157,6 @@ User space: For applications to run in unprivileged user mode Kernel space: For System calls APIs: man section 2

to be continue…

-

\documentclass[12pt,twoside,a4paper]{article} -\begin{document} -\begin{tabular}{|c|c|c|} -\hline -A & B & C \ -\hline -1 & 2 & 3 \ -\hline -4 & 5 & 6 -\ -\hline -\end{tabular} -\end{document}

diff --git a/posts/5/index.html b/posts/5/index.html new file mode 100644 index 0000000..8d9484a --- /dev/null +++ b/posts/5/index.html @@ -0,0 +1,1450 @@ + + + + + + + + + + + + + +Escape Sequences + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+

Escape Sequences

+ +
+
+ + + +
+
+ + + +
+
+ +
+ +
+ +
+

copied from github in case one day it disappears

+

more information could visit vt100 User Guide

+
+

ANSI Escape Sequences

+

Standard escape codes are prefixed with Escape:

+
    +
  • Ctrl-Key: ^[
  • +
  • Octal: \033
  • +
  • Unicode: \u001b
  • +
  • Hexadecimal: \x1B
  • +
  • Decimal: 27
  • +
+

Followed by the command, somtimes delimited by opening square bracket ([), known as a Control Sequence Introducer (CSI), optionally followed by arguments and the command itself.

+

Arguments are delimeted by semi colon (;).

+

For example:

+
\x1b[1;31m  # Set style to bold, red foreground.
+

Sequences

+
    +
  • ESC - sequence starting with ESC (\x1B)
  • +
  • CSI - Control Sequence Introducer: sequence starting with ESC [ or CSI (\x9B)
  • +
  • DCS - Device Control String: sequence starting with ESC P or DCS (\x90)
  • +
  • OSC - Operating System Command: sequence starting with ESC ] or OSC (\x9D)
  • +
+

Any whitespaces between sequences and arguments should be ignored. They are present for improved readability.

+

General ASCII Codes

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NamedecimaloctalhexC-escapeCtrl-KeyDescription
BEL70070x07\a^GTerminal bell
BS80100x08\b^HBackspace
HT90110x09\t^IHorizontal TAB
LF100120x0A\n^JLinefeed (newline)
VT110130x0B\v^KVertical TAB
FF120140x0C\f^LFormfeed (also: New pageNP)
CR130150x0D\r^MCarriage return
ESC270330x1B\e*^[Escape character
DEL1271770x7F<none><none>Delete character
+
+
+

Note: Some control escape sequences, like \e for ESC, are not guaranteed to work in all languages and compilers. It is recommended to use the decimal, octal or hex representation as escape code.

+
+
+

Note: The Ctrl-Key representation is simply associating the non-printable characters from ASCII code 1 with the printable (letter) characters from ASCII code 65 (“A”). ASCII code 1 would be ^A (Ctrl-A), while ASCII code 7 (BEL) would be ^G (Ctrl-G). This is a common representation (and input method) and historically comes from one of the VT series of terminals.

+
+

Cursor Controls

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ESC Code SequenceDescription
ESC[Hmoves cursor to home position (0, 0)
ESC[{line};{column}H
ESC[{line};{column}f
moves cursor to line #, column #
ESC[#Amoves cursor up # lines
ESC[#Bmoves cursor down # lines
ESC[#Cmoves cursor right # columns
ESC[#Dmoves cursor left # columns
ESC[#Emoves cursor to beginning of next line, # lines down
ESC[#Fmoves cursor to beginning of previous line, # lines up
ESC[#Gmoves cursor to column #
ESC[6nrequest cursor position (reports asESC[#;#R)
ESC Mmoves cursor one line up, scrolling if needed
ESC 7save cursor position (DEC)
ESC 8restores the cursor to the last saved position (DEC)
ESC[ssave cursor position (SCO)
ESC[urestores the cursor to the last saved position (SCO)
+
+

Note: Some sequences, like saving and restoring cursors, are private sequences and are not standardized. While some terminal emulators (i.e. xterm and derived) support both SCO and DEC sequences, they are likely to have different functionality. It is therefore recommended to use DEC sequences.

+
+

Erase Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ESC Code SequenceDescription
ESC[Jerase in display (same as ESC[0J)
ESC[0Jerase from cursor until end of screen
ESC[1Jerase from cursor to beginning of screen
ESC[2Jerase entire screen
ESC[3Jerase saved lines
ESC[Kerase in line (same as ESC[0K)
ESC[0Kerase from cursor to end of line
ESC[1Kerase start of line to the cursor
ESC[2Kerase the entire line
+
+

Note: Erasing the line won’t move the cursor, meaning that the cursor will stay at the last position it was at before the line was erased. You can use \r after erasing the line, to return the cursor to the start of the current line.

+
+

Colors / Graphics Mode

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ESC Code SequenceReset SequenceDescription
ESC[1;34;{...}mSet graphics modes for cell, separated by semicolon (;).
ESC[0mreset all modes (styles and colors)
ESC[1mESC[22mset bold mode.
ESC[2mESC[22mset dim/faint mode.
ESC[3mESC[23mset italic mode.
ESC[4mESC[24mset underline mode.
ESC[5mESC[25mset blinking mode
ESC[7mESC[27mset inverse/reverse mode
ESC[8mESC[28mset hidden/invisible mode
ESC[9mESC[29mset strikethrough mode.
+
+

Note: Some terminals may not support some of the graphic mode sequences listed above.

+
+
+

Note: Both dim and bold modes are reset with the ESC[22m sequence. The ESC[21m sequence is a non-specified sequence for double underline mode and only work in some terminals and is reset with ESC[24m.

+
+

Color codes

+

Most terminals support 8 and 16 colors, as well as 256 (8-bit) colors. These colors are set by the user, but have commonly defined meanings.

+

8-16 Colors

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Color NameForeground Color CodeBackground Color Code
Black3040
Red3141
Green3242
Yellow3343
Blue3444
Magenta3545
Cyan3646
White3747
Default3949
Reset00
+
+

Note: the Reset color is the reset code that resets all colors and text effects, Use Default color to reset colors only.

+
+

Most terminals, apart from the basic set of 8 colors, also support the “bright” or “bold” colors. These have their own set of codes, mirroring the normal colors, but with an additional ;1 in their codes:

+
# Set style to bold, red foreground.
+\x1b[1;31mHello
+# Set style to dimmed white foreground with red background.
+\x1b[2;37;41mWorld
+

Terminals that support the aixterm specification provides bright versions of the ISO colors, without the need to use the bold modifier:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Color NameForeground Color CodeBackground Color Code
Bright Black90100
Bright Red91101
Bright Green92102
Bright Yellow93103
Bright Blue94104
Bright Magenta95105
Bright Cyan96106
Bright White97107
+

256 Colors

+

The following escape codes tells the terminal to use the given color ID:

+ + + + + + + + + + + + + + + + + +
ESC Code SequenceDescription
ESC[38;5;{ID}mSet foreground color.
ESC[48;5;{ID}mSet background color.
+

Where {ID} should be replaced with the color index from 0 to 255 of the following color table:

+

256 Color table

+

The table starts with the original 16 colors (0-15).

+

The proceeding 216 colors (16-231) or formed by a 3bpc RGB value offset by 16, packed into a single value.

+

The final 24 colors (232-255) are grayscale starting from a shade slighly lighter than black, ranging up to shade slightly darker than white.

+

Some emulators interpret these steps as linear increments (256 / 24) on all three channels, although some emulators may explicitly define these values.

+

RGB Colors

+

More modern terminals supports Truecolor (24-bit RGB), which allows you to set foreground and background colors using RGB.

+

These escape sequences are usually not well documented.

+ + + + + + + + + + + + + + + + + +
ESC Code SequenceDescription
ESC[38;2;{r};{g};{b}mSet foreground color as RGB.
ESC[48;2;{r};{g};{b}mSet background color as RGB.
+
+

Note that ;38 and ;48 corresponds to the 16 color sequence and is interpreted by the terminal to set the foreground and background color respectively. Where as ;2 and ;5 sets the color format.

+
+

Screen Modes

+

Set Mode

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ESC Code SequenceDescription
ESC[={value}hChanges the screen width or type to the mode specified by value.
ESC[=0h40 x 25 monochrome (text)
ESC[=1h40 x 25 color (text)
ESC[=2h80 x 25 monochrome (text)
ESC[=3h80 x 25 color (text)
ESC[=4h320 x 200 4-color (graphics)
ESC[=5h320 x 200 monochrome (graphics)
ESC[=6h640 x 200 monochrome (graphics)
ESC[=7hEnables line wrapping
ESC[=13h320 x 200 color (graphics)
ESC[=14h640 x 200 color (16-color graphics)
ESC[=15h640 x 350 monochrome (2-color graphics)
ESC[=16h640 x 350 color (16-color graphics)
ESC[=17h640 x 480 monochrome (2-color graphics)
ESC[=18h640 x 480 color (16-color graphics)
ESC[=19h320 x 200 color (256-color graphics)
ESC[={value}lResets the mode by using the same values that Set Mode uses, except for 7, which disables line wrapping. The last character in this escape sequence is a lowercase L.
+

Common Private Modes

+

These are some examples of private modes, which are not defined by the specification, but are implemented in most terminals.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ESC Code SequenceDescription
ESC[?25lmake cursor invisible
ESC[?25hmake cursor visible
ESC[?47lrestore screen
ESC[?47hsave screen
ESC[?1049henables the alternative buffer
ESC[?1049ldisables the alternative buffer
+

Refer to the XTerm Control Sequences for a more in-depth list of private modes defined by XTerm.

+
+

Note: While these modes may be supported by the most terminals, some may not work in multiplexers like tmux.

+
+

Keyboard Strings

+
ESC[{code};{string};{...}p
+

Redefines a keyboard key to a specified string.

+

The parameters for this escape sequence are defined as follows:

+
    +
  • code is one or more of the values listed in the following table. These values represent keyboard keys and key combinations. When using these values in a command, you must type the semicolons shown in this table in addition to the semicolons required by the escape sequence. The codes in parentheses are not available on some keyboards. ANSI.SYS will not interpret the codes in parentheses for those keyboards unless you specify the /X switch in the DEVICE command for ANSI.SYS.
  • +
  • string is either the ASCII code for a single character or a string contained in quotation marks. For example, both 65 and “A” can be used to represent an uppercase A.
  • +
+
+

IMPORTANT: Some of the values in the following table are not valid for all computers. Check your computer’s documentation for values that are different.

+
+

List of keyboard strings

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
KeyCodeSHIFT+codeCTRL+codeALT+code
F10;590;840;940;104
F20;600;850;950;105
F30;610;860;960;106
F40;620;870;970;107
F50;630;880;980;108
F60;640;890;990;109
F70;650;900;1000;110
F80;660;910;1010;111
F90;670;920;1020;112
F100;680;930;1030;113
F110;1330;1350;1370;139
F120;1340;1360;1380;140
HOME (num keypad)0;71550;119--
UP ARROW (num keypad)0;7256(0;141)--
PAGE UP (num keypad)0;73570;132--
LEFT ARROW (num keypad)0;75520;115--
RIGHT ARROW (num keypad)0;77540;116--
END (num keypad)0;79490;117--
DOWN ARROW (num keypad)0;8050(0;145)--
PAGE DOWN (num keypad)0;81510;118--
INSERT (num keypad)0;8248(0;146)--
DELETE (num keypad)0;8346(0;147)--
HOME(224;71)(224;71)(224;119)(224;151)
UP ARROW(224;72)(224;72)(224;141)(224;152)
PAGE UP(224;73)(224;73)(224;132)(224;153)
LEFT ARROW(224;75)(224;75)(224;115)(224;155)
RIGHT ARROW(224;77)(224;77)(224;116)(224;157)
END(224;79)(224;79)(224;117)(224;159)
DOWN ARROW(224;80)(224;80)(224;145)(224;154)
PAGE DOWN(224;81)(224;81)(224;118)(224;161)
INSERT(224;82)(224;82)(224;146)(224;162)
DELETE(224;83)(224;83)(224;147)(224;163)
PRINT SCREEN----0;114--
PAUSE/BREAK----0;0--
BACKSPACE88127(0)
ENTER13--10(0
TAB90;15(0;148)(0;165)
NULL0;3------
A976510;30
B986620;48
C996630;46
D1006840;32
E1016950;18
F1027060;33
G1037170;34
H1047280;35
I1057390;23
J10674100;36
K10775110;37
L10876120;38
M10977130;50
N11078140;49
O11179150;24
P11280160;25
Q11381170;16
R11482180;19
S11583190;31
T11684200;20
U11785210;22
V11886220;47
W11987230;17
X12088240;45
Y12189250;21
Z12290260;44
14933--0;120
2506400;121
35135--0;122
45236--0;123
55337--0;124
65494300;125
75538--0;126
85642--0;126
95740--0;127
04841--0;129
-4595310;130
=6143-–0;131
[91123270;26
]93125290;27
92124280;43
;5958--0;39
'3934--0;40
,4460--0;51
.4662--0;52
/4763--0;53
`96126--(0;41)
ENTER (keypad)13--10(0;166)
/ (keypad)4747(0;142)(0;74)
* (keypad)42(0;144)(0;78)--
- (keypad)4545(0;149)(0;164)
+ (keypad)4343(0;150)(0;55)
5 (keypad)(0;76)53(0;143)--
+

Resources

+ + +
+ +
+
+ +
+
+ + +
+ + + + +
+
+
+ + + + + + + + + + diff --git a/posts/6/index.html b/posts/6/index.html new file mode 100644 index 0000000..6c2617d --- /dev/null +++ b/posts/6/index.html @@ -0,0 +1,359 @@ + + + + + + + + + + + + + +Mess with Bash(2) + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+

Mess with Bash(2)

+ +
+
+ + + +
+
+ + + +
+
+ +
+ +
+ +
+

More info is in this tutorial

+
+
+

all value expansions (ie. all syntax with a $ prefix) can only expand inside quoted arguments if the argument was double-quoted . Single quotes will turn the dollar-syntax into literal characters, causing bash to output the dollar rather than expand its value in-place!

+
+

“Value expansions ($...) must always be double-quoted.”

+

Never leave a value expansion unquoted.

+

Redirection

+

File Redirection

+

0 is standard input, 1 is standard output, 2 is standard error

+

[x] > file, [x] < file

+

Make File descriptor(FD) x write to / read from file.

+
+

echo hello > ~/World

+

read line < ~/Word

+

rm file 2>/dev/null

+
+

File Descriptor copying

+

[x] >& y, [x] <& y

+

make FD x write to / read from FD y’s stream

+
+

the connection to the stream used by FD y is copied to FD x

+

curl cip.cc > result 2>&1

+

ping localhost > result 2>&1

+
# exec can be used to change the file descriptors of bash itself,
+# and if you use an x that doesn't yet exist,
+# bash will create a new file descriptor ("plug") for you with that number.
+# - in command is to close new FD 3 we'd created before.
+# >&- is to close FD 1, <&- is to close FD0
+exec 3>&1 >mylog; echo moo; exec 1>&3 3>&-
+
+

Appending file redirection

+

[x] >> file

+

make FD x append to end of the file

+
+

A stream to file is opened for writing in append mode and is connected to file descriptor x. The regular file redirection operator > empties the file’s contents when it opens the file so that only your bytes will be in the file.

+

echo hello >> ~/world

+

echo world >> ~/world

+
+

Redirecting standard output and standard error

+

&>file

+

Make both FD 1 (standard output) and FD 2 (standard error) write to file

+
+

This is a convenience operator which does the same thing as >file 2>&1 but is more concise. Again, you can append rather than truncate by doubling the arrow: &>>file

+

ping localhost &>result

+
+

Here documents

+
<<delimiter
+	Here document
+delimiter
+

Make FD 0 read from the string between delimiters

+
+

Here-Documents are great for reading blocks of text to command line.

+
cat << EOF
+this is within here document
+I can write as many lines as I like
+and terminate with line of demiliter only
+EOF	//end of heredoc
+
+

Here strings

+

<<< string

+

Make FD 0 read from the string

+
+

Here strings are very similar to here documents but more concise. They are generally preferred over here documents.

+
cat <<< "This,
+is the here strings. tab will also be read."
+
+

Moving file decipher

+

[x]>&y-, [x]<&y-

+

Replace FD x with FD y and close FD y

+
+

Easy way of [x]>&y, y>&-

+
# 3>&1-: copy FD 1 to FD 3 and close FD 1.
+#  >&3-: copy FD 3 to FD 1 and close FD 3.
+exec 3>&1- >mylog; echo moo; exec >&3-
+
+

Reading and writing with file descriptor

+

[x] <> file

+

Open FD x for both reading and writing to file

+
+

The file descriptor at x is opened with a stream to the file that can be used for writing as well as reading bytes. Usually you’ll use two file descriptors for this. One of the rare cases where this is useful is when setting up a stream with a read/write device such as a network socket.

+
exec 5<>aFile
+cat >&5 "Hello world"	# make FD 1 write to where FD 5 currently writing, copy file descriptor FD 5 to FD 1
+cat <&5			# make FD 0 read from where FD 5 currently reading, copy file descriptor FD 5 to FD 0, then cat will send content to FD 1
+
+

Exercise

+
+

Q: fix exec 3>&2 2>log; echo 'Hello!'; exec 2>&3 so that the message is properly saved into the log file and such that FD 3 is properly closed afterwards:

+

A:

+
    +
  1. exec 3>&1- 3>log; echo 'Hello!'; exec 1>&3-
  2. +
  3. exec 3>&1 1>&- 3>log; echo 'Hello!'; exec 1>&3 3>&-
  4. +
+
+

Expansion

+

pathname expansion

+
    +
  1. +

    pattern expansion is performed by bash before command even execute

    +
    +

    file * will show info about all file in current directory. * will expand to content before file execute.

    +
    +
  2. +
  3. +

    A glob is the name of the type of pattern supported by the bash shell.

    +
    +

    basic glob name supported by bashexplanation

    +

    example

    +

    Those glob will only affect current directory, explicit expression is required to working on other directory. ls /sub/*

    +
    +
  4. +
  5. +

    extended glob can be enable to get more powerful but also easy confusing feature of bash

    +
    +

    bash: shopt -s extglob +zsh. : setopt extendedglob +explanation

    +

    !(my)* get expand because of * is outside !(), which makes it expland another whole pathname

    +
    +
  6. +
+

Command Substitution

+

we can expansion commands within commands, but must use double-quote "" instead of ''

+
# this will output contents in hello.h to screen
+cat hello.h
+
+# this will expand `cat hello.h` to real contents in 
+# file hello.h and concatenate to previous sentence
+echo "file hello.h contains contents of $(cat hello.h)"
+
+# this will output 'file hello.h contains contents of $(cat hello.h)'
+# without expand command in $()
+echo 'file hello.h contains contents of $(cat hello.h)'
+

In command, $() is called value expansion, it consists of value-expansion prefix $ and subshell (...). A subshell is essentially a small new bash process that is used to run a command while the main bash shell waits for the result.

+

Parameters

+

There are three kind of parameters:

+
    +
  1. Environment Parameter
  2. +
  3. Positional Parameter
  4. +
  5. Variables
  6. +
+

Environment Parameter

+

environment variables exist at the process level. That means they are not a feature of the bash shell, but rather a feature of any program process on your system. They can inherit by children, but children’s EV can’t be given to parent.

+

Positional Parameter

+

Just as name indicates, these kind of parameters indicate arguments’ position, and always starting from 0.

+

for example, imaging we have a script rename, arguments could be passed to it to extend its usage:

+

rename dir name there, we passed dir and name as argument, so that positional parameters in script would be $1 and $2, representing arguments respectively. after $2, such as $3 is unset since there has no more argument.

+
+

Positional Parameter is read-only

+
+

a new usage: bash -c 'ls "$1"' -- '/home'. This will working like ls /home, dash is necessary since it is first variable in shell we ran commands and it makes positional value of arguments populated after it stand as we expect in shell single-quoted command gonna run in.

+

Special Parameter

+

Special parameters are parameters whose name is a single symbolic character, they are used to request certain state information from the bash shell. Like positional parameter, they are read-only.

+

different kinds of special parameters and the information they hold

+

Variables

+

definition: name=value //no space around = like other programming language support

+

call: like command expansion, using variable is to expand it with prefix $, e.g. $name

+
    +
  • Keep in mind, Expansion should always be double-quoted *
  • +
+

Parameter expansion

+
+

GNU material

+
+

we expand parameters by prefixing their name with a $ symbol

+
+

e.g. name=me; echo hello "$name". hello me.

+
+

In addition, we can put braces ({ and }) around our parameter, which indicates where variable is about to begin and end.

+
+

e.g. name=orange; echo there are 4 "${name}s" there are 4 oranges.

+
name=orange
+echo "there are 4 ${name}s."	# there are 4 oranges.
+echo "there are 4 $names."	# there are 4 .
+

here, we put {}aroundnameso that bash can be told that suffix s is not a part of variable. otherwise, it will treat names as parameter and looking for its value, which is none in our example.

+
+

parameter expansion brings up a powerful feature: parameter expansion oerators

+
+

While expanding a parameter, it is possible to apply an operator to the expanding value without alternate original value.

+

I use these mostly

+
# remove string before pattern   	${name#pattern} shortest	${name##pattern} longest
+# remove string after pattern    	${name%pattern} longest 	${name%%pattern} shortest
+# delete first matching pattern		${name/pattern}
+# delete all matching pattern		${name//pattern}
+# substitute pattern with string 	${name//pattern/string}
+
+foo="foo-bar-foobar"
+echo ${foo#*-}		# echoes 'bar-foobar' (Removes 'foo-' because that matches '*-')
+echo ${foo##*-}		# echoes 'foobar' (Removes 'foo-bar-')
+echo ${foo%-*}		# echoes 'foo-bar'
+echo ${foo%%-*}		# echoes 'foo'
+echo ${foo/-}		# echoes 'foobar-foobar'
+echo ${foo//-}		# echoes 'foobarfoobar'
+echo ${foo//-/_}	# echoes 'foo_bar_foobar'
+
+

part of operators as shown picture

+ +
+ +
+
+ +
+
+ + +
+ + + + +
+
+
+ + + + + + + + + + diff --git a/posts/7/index.html b/posts/7/index.html new file mode 100644 index 0000000..788f339 --- /dev/null +++ b/posts/7/index.html @@ -0,0 +1,164 @@ + + + + + + + + + + + + + +Past Is Great + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+

Past Is Great

+ +
+
+ + + +
+
+ + + +
+
+ +
+ +
+ +

Lately, there’s a sign has been keeping jumping out in front of my eyes. That the past is great!

+

First is in the movie Midnight in Paris, directed by Woody Allen, which I just finished a week ago. It tells a story of how a screen writer love 20th century because his loving artists all living in it. Though he finally realize that he loves past because the present is imperfect.

+

Second is my YouTube keeps suggesting songs that got me reminiscence bump. Such songs that remind me when the time power cut is regular and the phone has not yet existed. I still remember the feel when I am wrapped in quilt and watch TV in the cold night… dizzy.

+

Third just happened now, I was gonna start watching Doraemon, and the title of the episode I’m getting at is ‘Past is Great’, seriously???

+

even two of them would tell me the present is better than past, I still miss past. Midnight in Paris said we love past because present unsatisfied. And ‘Past in Great’ shows us comparing of ancient and modern lives style. Both views are most people miss about past, either think their life sucks or just wanna experience life in past.

+

Well, I’m not both… I miss past is that it is fixed, it is unchangeable. No matter what we do now, past is past, it right there, waiting to be read. this feel just like when I watch shows or movies. I’d want to know what ending it will be, and release my imagination along with shows to get that result.

+

Same thing happens here. Few scenes I remember, or the music I think familiar, but I don’t know when or where I experienced it, I would start my imagination. Maybe I was doing something funny, maybe I was going to somewhere nice, maybe… maybe… then, I got here. The beauty part is, I always thought nice thing, and it always make me feel ease. That’s good enough for me.

+

I said there’s this sign… Actually, not really. Just some shit things happend recently that make me want to run away. The ‘sign’ just is what I want to see now, not that it really a sign.

+ +
+ +
+
+ +
+
+ + +
+ + + + +
+
+
+ + + + + + + + + + diff --git a/posts/index.html b/posts/index.html index 51d8a13..30b6e23 100644 --- a/posts/index.html +++ b/posts/index.html @@ -29,8 +29,8 @@ "accountablePerson" : "garhve", "copyrightHolder" : "garhve", "copyrightYear" : "2022", - "datePublished": "2022-09-03 14:33:37 \u002b0800 CST", - "dateModified" : "2022-09-03 14:33:37 \u002b0800 CST", + "datePublished": "2022-11-07 09:16:15 \u002b0800 CST", + "dateModified" : "2022-11-07 09:16:15 \u002b0800 CST", "url" : "https:\/\/blog.garhve.com\/posts\/", "keywords" : [ ] } @@ -95,6 +95,45 @@

2022

+
+
+ +
+
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
diff --git a/posts/index.xml b/posts/index.xml index 675d18e..7c1d263 100644 --- a/posts/index.xml +++ b/posts/index.xml @@ -6,7 +6,43 @@ Recent content in Posts on blog | garhve's hub Hugo -- gohugo.io en-us - Sat, 03 Sep 2022 14:33:37 +0800 + Mon, 07 Nov 2022 09:16:15 +0800 + + Past Is Great + https://blog.garhve.com/posts/7/ + Mon, 07 Nov 2022 09:16:15 +0800 + + https://blog.garhve.com/posts/7/ + Lately, there’s a sign has been keeping jumping out in front of my eyes. That the past is great! +First is in the movie Midnight in Paris, directed by Woody Allen, which I just finished a week ago. It tells a story of how a screen writer love 20th century because his loving artists all living in it. Though he finally realize that he loves past because the present is imperfect. + + + + Mess with Bash(2) + https://blog.garhve.com/posts/6/ + Thu, 29 Sep 2022 09:43:02 +0800 + + https://blog.garhve.com/posts/6/ + More info is in this tutorial +all value expansions (ie. all syntax with a $ prefix) can only expand inside quoted arguments if the argument was double-quoted . Single quotes will turn the dollar-syntax into literal characters, causing bash to output the dollar rather than expand its value in-place! +&ldquo;Value expansions ($...) must always be double-quoted.&rdquo; +Never leave a value expansion unquoted. +Redirection File Redirection 0 is standard input, 1 is standard output, 2 is standard error + + + + Escape Sequences + https://blog.garhve.com/posts/5/ + Mon, 12 Sep 2022 09:02:06 +0800 + + https://blog.garhve.com/posts/5/ + copied from github in case one day it disappears +more information could visit vt100 User Guide +ANSI Escape Sequences Standard escape codes are prefixed with Escape: +Ctrl-Key: ^[ Octal: \033 Unicode: \u001b Hexadecimal: \x1B Decimal: 27 Followed by the command, somtimes delimited by opening square bracket ([), known as a Control Sequence Introducer (CSI), optionally followed by arguments and the command itself. +Arguments are delimeted by semi colon (;). + + Architecture of Linux Kernel https://blog.garhve.com/posts/4/ -- cgit v1.2.3-70-g09d2