Skip to main content
deleted 33 characters in body
Source Link
slm
  • 379.8k
  • 127
  • 793
  • 897

I amI'm using following script for Shortest Sub-string Match in String handling.

 filename="bash.string.txt"

    echo ${filename#*.}

It gives following output.

string.txt

Here is an explanation of above example (Link: https://www.thegeekstuff.com/2010/07/bash-string-manipulation):

The above example deletes the shortest match of $substring from front of $string. In the first echo statement substring ‘*.’ matches the characters and a dot, and # strips from the front of the string, so it strips the substring “bash.” from the variable called filename.

Than iThen I changed the code as below:

 filename="bashshell.string.txt"

echo ${filename#*.}

I just extended the first string from bash. to bashshell. and expecting the output "bashshell.txt" according to explanation given above. But instead it gives me same output as first example. i

i.e. string.txt

So do iI misunderstood thatthe concept? If yes than how it actually works?

Thanks in advance.

I am using following script for Shortest Sub-string Match in String handling.

 filename="bash.string.txt"

    echo ${filename#*.}

It gives following output.

string.txt

Here is an explanation of above example (Link: https://www.thegeekstuff.com/2010/07/bash-string-manipulation):

The above example deletes the shortest match of $substring from front of $string. In the first echo statement substring ‘*.’ matches the characters and a dot, and # strips from the front of the string, so it strips the substring “bash.” from the variable called filename.

Than i changed the code as below:

 filename="bashshell.string.txt"

echo ${filename#*.}

I just extended the first string from bash. to bashshell. and expecting the output "bashshell.txt" according to explanation given above. But instead it gives me same output as first example. i.e. string.txt

So do i misunderstood that concept? If yes than how it actually works?

Thanks in advance.

I'm using following script for Shortest Sub-string Match in String handling.

filename="bash.string.txt"

echo ${filename#*.}

It gives following output.

string.txt

Here is an explanation of above example (Link: https://www.thegeekstuff.com/2010/07/bash-string-manipulation):

The above example deletes the shortest match of $substring from front of $string. In the first echo statement substring ‘*.’ matches the characters and a dot, and # strips from the front of the string, so it strips the substring “bash.” from the variable called filename.

Then I changed the code as below:

filename="bashshell.string.txt"

echo ${filename#*.}

I just extended the first string from bash. to bashshell. and expecting the output "bashshell.txt" according to explanation given above. But instead it gives me same output as first example.

i.e. string.txt

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

Source Link
Dip
  • 740
  • 3
  • 9
  • 13

What is the concept of Shortest Sub-string Match in Unix Shell?

I am using following script for Shortest Sub-string Match in String handling.

 filename="bash.string.txt"

    echo ${filename#*.}

It gives following output.

string.txt

Here is an explanation of above example (Link: https://www.thegeekstuff.com/2010/07/bash-string-manipulation):

The above example deletes the shortest match of $substring from front of $string. In the first echo statement substring ‘*.’ matches the characters and a dot, and # strips from the front of the string, so it strips the substring “bash.” from the variable called filename.

Than i changed the code as below:

 filename="bashshell.string.txt"

echo ${filename#*.}

I just extended the first string from bash. to bashshell. and expecting the output "bashshell.txt" according to explanation given above. But instead it gives me same output as first example. i.e. string.txt

So do i misunderstood that concept? If yes than how it actually works?

Thanks in advance.