Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this BASH shell script excerpt do?

Tags:

regex

bash

shell

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?

like image 805
ViniH Avatar asked Jun 22 '26 15:06

ViniH


1 Answers

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.

like image 97
Eugeniu Rosca Avatar answered Jun 25 '26 04:06

Eugeniu Rosca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!