https://github.com/mrquincle/superscripts
Bunch of bash scripts that tend to be useful over time
https://github.com/mrquincle/superscripts
Last synced: 3 months ago
JSON representation
Bunch of bash scripts that tend to be useful over time
- Host: GitHub
- URL: https://github.com/mrquincle/superscripts
- Owner: mrquincle
- Created: 2012-09-25T13:07:01.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2022-06-21T09:05:24.000Z (over 3 years ago)
- Last Synced: 2025-04-06T10:43:56.971Z (6 months ago)
- Language: Shell
- Size: 212 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Superscripts
A bunch of scripts for all kind of purposes... :-)## Thing I like
These are just .sh or .bash scripts, but also such scripts have many little tricks you only learn over times.
To require an argument for a script:
file=${1:? "$0 requires \"file\" as first argument"}
Lowercase:var_lc=$(echo $var | tr "[:upper:]" "[:lower:]")
Remove temporary file or directory, even if script fails:
tmpdir=$(mktemp -d -t prefixXXXXX)
trap 'rm -rf "$tmpdir"' EXITCreate array from variable `array_txt`:
IFS=$'\n' read -d '' -r -a array <<< "$array_txt"
And of course its length:
array_length=${#array[@]}
Disable globbing:
shopt -s nullglob
Remove comma from last line in file:
sed -i -e '$s|,||' "$file"
Split a file based on context lines (for example a json array):
csplit -s -n6 -f "$file" '/metadata/-1' '{*}'
Json manipulations, use underscore-cli, say input is `input.json` and we want to get the field items and then snippet:
< input.json underscore select '.items .snippet' > result.json
## Copyrights
The copyrights (2014) belong to:- Author: Anne van Rossum
- Almende B.V., http://www.almende.com and DoBots B.V., http://www.dobots.nl
- Rotterdam, The Netherlands