ViniH
ViniH

Reputation: 756

What does this BASH shell script excerpt do?

Can you explain the following code please (assume that HOST contains a string):

HOST=${HOST//$'\n'/}

If the above line was declared inside a function, would the variable "HOST" be available to other functions in the same script?

Upvotes: 3

Views: 188

Answers (1)

Eugeniu Rosca
Eugeniu Rosca

Reputation: 5305

According to Substring Replacement subchapter from the ABS guide:

HOST=${HOST//$'\n'/}

removes all occurrences of the newline character $'\n' in the HOST variable.

If the above line was declared inside a function, would the variable HOST be available to other functions in the same script?

Yes, assuming HOST wasn't declared using bash local keyword.

Upvotes: 9

Related Questions