From c2fc594db46a9c1e0c6522f394805d81ce77b7af Mon Sep 17 00:00:00 2001 From: I-Man Ng Date: Thu, 9 May 2019 15:41:47 +0800 Subject: [PATCH 1/4] Improve 'get the first character of variable Thanks to Masta's command on Reddit --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5479404..3616e2c 100644 --- a/README.md +++ b/README.md @@ -1018,9 +1018,13 @@ echo ${#var} ``` ##### get the first character of the variable ```bash -var="some string" +var=string +echo "${var:0:1}" +#s + +#or echo ${var%%"${var#?}"} -#s + ``` ##### remove the first or last string from variable ```bash From 6ecd7cf784cabbad67d6ad6ca8a6b4ad56871515 Mon Sep 17 00:00:00 2001 From: I-Man Ng Date: Thu, 9 May 2019 16:04:33 +0800 Subject: [PATCH 2/4] Fixed some typos and bugs Thanks to Crestwave's correction on Reddit. --- README.md | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3616e2c..47709d4 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,8 @@ Ctrl + d : if you've type something, Ctrl + d deletes the character under the cu Ctrl + k : delete all text from the cursor to the end of line. Ctrl + x + backspace : delete all text from the beginning of line to the cursor. Ctrl + t : transpose the character before the cursor with the one under the cursor, press Esc + t to transposes the two words before the cursor. -Ctrl + w : delete the word before the cursor. -Ctrl + u : delete the line before the cursor. +Ctrl + w : cut the word before the cursor; then Ctrl + y paste it +Ctrl + u : cut the line before the cursor; then Ctrl + y paste it Ctrl + x + Ctrl + e : launch editor define by $EDITOR ``` ##### Change case @@ -877,7 +877,7 @@ find . -type d ##### Edit all files under current directory (e.g. replace 'www' with 'ww') ```bash -find . name '*.php' -exec sed -i 's/www/w/g' {} \; +find . -name '*.php' -exec sed -i 's/www/w/g' {} \; ``` if no subdirectory @@ -944,7 +944,7 @@ if ((x >= 5)); then … if ((j==u+2)) # Use [[ ]] for comparison -if [[$age >21]] +if [[ $age -gt 21 ]] ``` [More if commands](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html) @@ -1200,7 +1200,7 @@ curl https://transfer.sh/tG8rM/filename.txt -o filename.txt ```bash data=file.txt url=http://www.example.com/$data -if [! -s $data];then +if [ ! -s $data ];then echo "downloading test data..." wget $url fi @@ -1495,7 +1495,12 @@ cp -rp /path/to/directory ##### Store current directory ```bash -pushd . $popd ;dirs -l +pushd . +# then pop +popd +#pushd . +#or use dirs to display the list of currently remembered directories. +dirs -l ``` ##### Show disk usage @@ -2491,6 +2496,12 @@ echo -e ' \t ' ##### Array ```bash +declare -a array=() + +#or +declare array=() + +#or associative array declare -A array=() ``` From 7643e712fdb477db0298e868a37c229467883b35 Mon Sep 17 00:00:00 2001 From: I-Man Ng Date: Thu, 9 May 2019 16:07:23 +0800 Subject: [PATCH 3/4] fixed typos --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 47709d4..da69e4f 100644 --- a/README.md +++ b/README.md @@ -1496,9 +1496,10 @@ cp -rp /path/to/directory ```bash pushd . + # then pop popd -#pushd . + #or use dirs to display the list of currently remembered directories. dirs -l ``` From bbd2974d41c501df7baea84a92710e4437f47273 Mon Sep 17 00:00:00 2001 From: I-Man Ng Date: Thu, 9 May 2019 19:19:25 +0800 Subject: [PATCH 4/4] Fix typo Thank Costin Stefan for the reminder --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index da69e4f..517e233 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Ctrl + x + Ctrl + e : launch editor define by $EDITOR Esc + u # converts text from cursor to the end of the word to uppercase. Esc + l -# converts text from cursor to the end of the word to uppercase. +# converts text from cursor to the end of the word to case. Esc + c # converts letter under the cursor to uppercase. ```