Skip to main content
added 29 characters in body
Source Link
Noam Manos
  • 1.1k
  • 11
  • 13

To check if variable has only spaces, including in a multi-linesline variable with spaces, try this:

[[ $var = *[$" \t\n"]* ]] 

Or with xargs:

[[ -z $(echo $var | xargs) ]] 

Or with sed:

[[ -z $(sed "/^$/d" <<< $var) ]] 

To check a multi-lines variable with spaces, try this:

[[ $var = *[$" \t\n"]* ]] 

Or with xargs:

[[ -z $(echo $var | xargs) ]] 

Or with sed:

[[ -z $(sed "/^$/d" <<< $var) ]] 

To check if variable has only spaces, including in a multi-line variable, try this:

[[ $var = *[$" \t\n"]* ]] 

Or with xargs:

[[ -z $(echo $var | xargs) ]] 

Or with sed:

[[ -z $(sed "/^$/d" <<< $var) ]] 
added 62 characters in body; edited body
Source Link
Noam Manos
  • 1.1k
  • 11
  • 13

ForTo check a multi-lines variable with spaces, try this:

[[ $var = *[$'*[$" \t\n']*\t\n"]* ]] 

Or with xargs:

[[ -z $(echo $var | xargs) ]] 

Or with sed:

[[ -z $(sed '"/^$/d'd" <<< $var) ]] 

For multi-lines variable with spaces, try this:

[[ $var = *[$' \t\n']* ]] 

Or with sed:

[[ -z $(sed '/^$/d' <<< $var) ]] 

To check a multi-lines variable with spaces, try this:

[[ $var = *[$" \t\n"]* ]] 

Or with xargs:

[[ -z $(echo $var | xargs) ]] 

Or with sed:

[[ -z $(sed "/^$/d" <<< $var) ]] 
deleted 29 characters in body
Source Link
Noam Manos
  • 1.1k
  • 11
  • 13

With regex there's an ultimate way to check forFor multi-lines variable with spaces, try this:

[[ $var =~= \s**[$' \t\n']* ]] 

Unlike other approaches here, it also includes multi-lines variableOr with spaces.sed:

[[ -z $(sed '/^$/d' <<< $var) ]] 

With regex there's an ultimate way to check for spaces:

[[ $var =~ \s* ]] 

Unlike other approaches here, it also includes multi-lines variable with spaces.

For multi-lines variable with spaces, try this:

[[ $var = *[$' \t\n']* ]] 

Or with sed:

[[ -z $(sed '/^$/d' <<< $var) ]] 
Post Undeleted by Noam Manos
Post Deleted by Noam Manos
Source Link
Noam Manos
  • 1.1k
  • 11
  • 13
Loading