From 53d7e27db404fa17545ffc759f7905c4a1e77757 Mon Sep 17 00:00:00 2001 From: Frank Deng Date: Mon, 23 Jan 2017 22:19:30 +0800 Subject: [PATCH] Update README.md --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index df6ca81..911878e 100644 --- a/README.md +++ b/README.md @@ -203,6 +203,15 @@ Notes: 5 ``` +- Iterate on command line arguments containing whitespace: + +```sh +while [ -n "${1}" ]; do + FILENAME="${1}"; + #Do some works on "${FILENAME}" + shift 1; +done; +``` ## Processing files and data @@ -253,6 +262,7 @@ Notes: repren --renames --from '(.*)\.bak' --to '\1' *.bak # Same as above, using rename, if available: rename 's/\.bak$//' *.bak + rename 's/(.*)\.bak/$1/' *.bak ``` - As the man page says, `rsync` really is a fast and extraordinarily versatile file copying tool. It's known for synchronizing between machines but is equally useful locally. When security restrictions allow, using `rsync` instead of `scp` allows recovery of a transfer without restarting from scratch. It also is among the [fastest ways](https://web.archive.org/web/20130929001850/http://linuxnote.net/jianingy/en/linux/a-fast-way-to-remove-huge-number-of-files.html) to delete large numbers of files: @@ -381,6 +391,13 @@ A few examples of piecing together commands: } ``` +- Extract basename and extension from a given filename under bash shell without using any external commands: + +```sh +FILENAME='README.1.md'; +BASENAME="${FILENAME%.*}"; # Shows "README.1" +EXTENSION="${FILENAME##*.}"; # Shows "md" +``` ## Obscure but useful