0

What does the following bash command do?

"${ctp// /}"

I want to check whether a variable is composed of an empty string or is all spaces, so that I can assign a default value.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Dilna
  • 405
  • 1
  • 6

1 Answers1

0

It removes any space characters.

Parameter Expansion expands parameters: $foo, $1. You can use it to perform string or array operations: "${file%.mp3}", "${0##*/}", "${files[@]: -4}". They should always be quoted.
See: http://mywiki.wooledge.org/BashFAQ/073 and "Parameter Expansion" in man bash.
Also see http://wiki.bash-hackers.org/syntax/pe

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
  • 1
    _raises an eyebrow re: answering a duplicate_ – Charles Duffy Mar 12 '23 at 22:46
  • Do you have the link Charles? – Gilles Quénot Mar 12 '23 at 22:47
  • If you didn't consider the linked duplicate at the time of my earlier comment acceptable, how about https://stackoverflow.com/questions/34789149/what-is-the-meaning-of-in-bash-parameter-expansions ? – Charles Duffy Mar 12 '23 at 22:51
  • Sure. And an eyebrow raise is not a downvote (which is what I'd do if I thought this was a bad answer). That said, what I do personally when I answer a question that looks off-topic is set the community-wiki flag so it doesn't look like I'm trying to farm rep by playing at the edge of the rules. – Charles Duffy Mar 14 '23 at 15:44