e.g hostname = "test.test.test", then after removing result should be like "testtesttest"
The tr command (short for translate) is used to translate, squeeze, and delete characters from a string. You can also use tr to remove characters from a string. For demonstration purposes, we will use a sample string and then pipe it to the tr command.
The commandline is interpreted by the shell, using the first \ to escape the second one, so one \ is passed literally to grep. The dot . is not special to the shell, so it is passed verbatim anyway. Grep then reads the (single) \ and uses it to escape the dot . .
In Bash (and ksh, zsh, dash, etc.), you can use parameter expansion with % which will remove characters from the end of the string or # which will remove characters from the beginning of the string. If you use a single one of those characters, the smallest matching string will be removed.
Here are all the ways in which variables are substituted in Shell: ${variable} This command substitutes the value of the variable. ${variable:-word} If a variable is null or if it is not set, word is substituted for variable.
$ foo=test.test.test $ echo "${foo//./}" testtesttest
You can also pipe into
tr -d '.'
But the best way of doing this is not to use an external command and use shell built in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With