Friday, 19 August 2011
Save wrong line bash
A simple thing to do when you realize you just typed the wrong line is hit Ctrl+C; if you want to keep the line, but need to execute something else first, begin a new line with a back slash - \, then Ctrl+C. The line will remain in your history.
Latex Dashes
Hyphen: daughter-in-law, X-rated\\
En dash: pages 13--67\\
Em dash: yes---or no? \\
Minus sign: $0$, $1$ and $-1$
En dash: pages 13--67\\
Em dash: yes---or no? \\
Minus sign: $0$, $1$ and $-1$
Bash trim filename
However, buried in there is a section on Parameter Substitution which tells us that $foo is really a shorthand for ${foo} which is really the simplest case of several ${foo:operators} and similar constructs.
- Given:
- foo=/tmp/my.dir/filename.tar.gz
- We can use these expressions:
- path = ${foo%/*}
- To get: /tmp/my.dir (like dirname)
- file = ${foo##*/}
- To get: filename.tar.gz (like basename)
- base = ${file%%.*}
- To get: filename
- ext = ${file#*.}
- To get: tar.gz
-
- ${variable%pattern}
- Trim the shortest match from the end
- ${variable##pattern}
- Trim the longest match from the beginning
- ${variable%%pattern}
- Trim the longest match from the end
- ${variable#pattern}
- Trim the shortest match from the beginning
Subscribe to:
Posts (Atom)