Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 6
    From man test: -z STRING - the length of STRING is zero. If you want to remove all spaces in $param, use ${param// /} Commented Jul 28, 2014 at 9:27
  • 7
    WOW there is not a simple trim() function built-in to any *nix at all? So many different hacks to achieve something so simple... Commented Mar 29, 2016 at 3:09
  • 6
    @ADTC $(sed 's/^\s+|\s+$//g' <<< $string) seems simple enough to me. Why reinvent the wheel? Commented May 19, 2016 at 16:53
  • 4
    Because it could be shinier Commented Jul 13, 2016 at 17:08
  • 2
    @Noah [ is equivalent to test. Sometimes it used to be a symlink. But [[ is BASH specific and there are many differences to program test. The reason of creating [[ was to make it easier to construct conditions. For that purpose it can't be the same as '[' or test. Commented Jan 25, 2021 at 1:22