A
A
Andrey Myvrenik2015-06-14 15:09:04
bash
Andrey Myvrenik, 2015-06-14 15:09:04

What are operations with a string in a variable like "${var//./}" called, and where can I find more information about these possibilities?

In writing scripts, I often use similar things that I once saw in other people's scripts and I know about them no more than that this works.
Let's say we have a variable: With its contents, you can perform similar manipulations:
foo='1.2.3.4.5'

echo ${foo/./}    # 12.3.4.5
echo ${foo//./}   # 12345
echo ${foo%.*}    # 1.2.3.4
echo ${foo%%.*}   # 1
echo ${foo#*.}    # 2.3.4.5
echo ${foo##*.}   # 5

What is it specifically called and where can I learn more about such operations?
explainshell.com ignores and doesn't explain it .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konkase, 2015-06-14
@gim0

Source: - Advanced Bash-Scripting Guide (Chapter 10. Manipulating Variables)

V
Valentine, 2015-06-14
@vvpoloskin

This is called string operations, and here are some examples.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question