Check out my first novel, midnight's simulacra!
Shell: Difference between revisions
From dankwiki
No edit summary |
No edit summary |
||
Line 8: | Line 8: | ||
==Useful functions== | ==Useful functions== | ||
< | <source> | ||
isnumber() { | isnumber() { | ||
case "$1" in | case "$1" in | ||
Line 15: | Line 15: | ||
esac | esac | ||
} | } | ||
</ | </source> |
Revision as of 04:59, 9 November 2022
IFS
To set IFS to newline, use IFS=$'\n'. This allows find output containing horizontal whitespace to be picked up and used in e.g. for loop.
- If you can use the output with xargs, then just use find's -print0 predicate and xargs's -0 option.
Redirects
- stderr to pipe, without stdout: 2>&1 >/dev/null |
Useful functions
isnumber() {
case "$1" in
''|*[!0-9]*) echo "not a number: $1" >&2 ; return 1 ; ;;
*) return 0
esac
}