Shell: Difference between revisions

Created page with "==IFS== To set IFS to newline, use IFS=$'\n'. This allows <tt>find</tt> output containing horizontal whitespace to be picked up and used in e.g. <tt>for</tt> loop. * If you ca..."
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:
To set IFS to newline, use IFS=$'\n'. This allows <tt>find</tt> output containing horizontal whitespace to be picked up and used in e.g. <tt>for</tt> loop.
To set IFS to newline, use IFS=$'\n'. This allows <tt>find</tt> output containing horizontal whitespace to be picked up and used in e.g. <tt>for</tt> loop.
* If you can use the output with <tt>xargs</tt>, then just use <tt>find</tt>'s <tt>-print0</tt> predicate and <tt>xargs</tt>'s <tt>-0</tt> option.
* If you can use the output with <tt>xargs</tt>, then just use <tt>find</tt>'s <tt>-print0</tt> predicate and <tt>xargs</tt>'s <tt>-0</tt> option.
==Redirects==
* stderr to pipe, without stdout: <tt>2>&1 >/dev/null |</tt>
==Useful functions==
<syntaxhighlight lang="sh">
isnumber() {
  case "$1" in
    ''|*[!0-9]*) echo "not a number: $1" >&2 ; return 1 ; ;;
    *) return 0
  esac
}
</syntaxhighlight>