Skip to main content
added 18 characters in body
Source Link
ilkkachu
  • 147.9k
  • 16
  • 268
  • 441

So do I misunderstood the concept? If yes than how it actually works?

Yes the notation ${var#*.} is truncatingremoving everything from the beginning of the string up to the character dot (..). It's doing what you asked of it, your pattern was star dot:

*.

So it will match everything up to the 1st dot from the start of the string, the one after the word bash.

bash.string.txt
    ^---------------- it's splitting here

Examples

$ str="bash.string.txt"
$ echo "${str#*.}"
string.txt

$ str="bash1.string.txt"
$ echo "${str#*.}"
string.txt

$ str="bash1.string1.txt"
$ echo "${str#*.}"
string1.txt

See when I put the 1 on the left side of the 1st ... This notation is truncating everything up to the 1st dot.

So do I misunderstood the concept? If yes than how it actually works?

Yes the notation ${var#*.} is truncating everything from the beginning of the string up to the character dot (.). It's doing what you asked of it, your pattern was star dot:

*.

So it will match everything up to the 1st dot after the word bash.

bash.string.txt
    ^---------------- it's splitting here

Examples

$ str="bash.string.txt"
$ echo "${str#*.}"
string.txt

$ str="bash1.string.txt"
$ echo "${str#*.}"
string.txt

$ str="bash1.string1.txt"
$ echo "${str#*.}"
string1.txt

See when I put the 1 on the left side of the 1st .. This notation is truncating everything up to the 1st dot.

So do I misunderstood the concept? If yes than how it actually works?

Yes the notation ${var#*.} is removing everything from the beginning of the string up to the character dot (.). It's doing what you asked of it, your pattern was star dot:

*.

So it will match everything up to the 1st dot from the start of the string, the one after the word bash.

bash.string.txt
    ^---------------- it's splitting here

Examples

$ str="bash.string.txt"
$ echo "${str#*.}"
string.txt

$ str="bash1.string.txt"
$ echo "${str#*.}"
string.txt

$ str="bash1.string1.txt"
$ echo "${str#*.}"
string1.txt

See when I put the 1 on the left side of the 1st .. This notation is truncating everything up to the 1st dot.

edited body
Source Link
slm
  • 379.8k
  • 127
  • 793
  • 897

So do I misunderstood the concept? If yes than how it actually works?

Yes the notation ${var#*.} is truncating everything from the beginning of the string up to the character dot (.). It's doing what you asked of it, your pattern was star dot:

*.

So it will match everything up to the 1st dot after the word bash.

bash.string.txt
    ^---------------- it's splitting here

Examples

$ str="bash.string.txt"
$ echo "${str#*.}"
string.txt

$ str="bash1.string.txt"
$ echo "${str#*.}"
string.txt

$ str="bash1.string1.txt"
$ echo "${str#*.}"
string1.txt

See when I put the 1 on the left side of the 1st .. This notation is truncating everything up to the 1st dot.

bash.string.txt
    ^---------------- it's splitting here

So do I misunderstood the concept? If yes than how it actually works?

Yes the notation ${var#*.} is truncating everything from the beginning of the string up to the character dot (.). It's doing what you asked of it, your pattern was star dot:

*.

So it will match everything up to the 1st dot after the word bash.

Examples

$ str="bash.string.txt"
$ echo "${str#*.}"
string.txt

$ str="bash1.string.txt"
$ echo "${str#*.}"
string.txt

$ str="bash1.string1.txt"
$ echo "${str#*.}"
string1.txt

See when I put the 1 on the left side of the 1st .. This notation is truncating everything up to the 1st dot.

bash.string.txt
    ^---------------- it's splitting here

So do I misunderstood the concept? If yes than how it actually works?

Yes the notation ${var#*.} is truncating everything from the beginning of the string up to the character dot (.). It's doing what you asked of it, your pattern was star dot:

*.

So it will match everything up to the 1st dot after the word bash.

bash.string.txt
    ^---------------- it's splitting here

Examples

$ str="bash.string.txt"
$ echo "${str#*.}"
string.txt

$ str="bash1.string.txt"
$ echo "${str#*.}"
string.txt

$ str="bash1.string1.txt"
$ echo "${str#*.}"
string1.txt

See when I put the 1 on the left side of the 1st .. This notation is truncating everything up to the 1st dot.

Source Link
slm
  • 379.8k
  • 127
  • 793
  • 897

So do I misunderstood the concept? If yes than how it actually works?

Yes the notation ${var#*.} is truncating everything from the beginning of the string up to the character dot (.). It's doing what you asked of it, your pattern was star dot:

*.

So it will match everything up to the 1st dot after the word bash.

Examples

$ str="bash.string.txt"
$ echo "${str#*.}"
string.txt

$ str="bash1.string.txt"
$ echo "${str#*.}"
string.txt

$ str="bash1.string1.txt"
$ echo "${str#*.}"
string1.txt

See when I put the 1 on the left side of the 1st .. This notation is truncating everything up to the 1st dot.

bash.string.txt
    ^---------------- it's splitting here