Results 1 to 4 of 4

Thread: Bash: Please explain ${var##*.}

  1. #1
    Join Date
    Apr 2011
    Beans
    30
    Distro
    Ubuntu 10.04 Lucid Lynx

    Bash: Please explain ${var##*.}

    I'm using bash to find the last part of a string e.g. 'myfile.3' - I found a method which works, but I don't know why!

    What should I be googling to find out more about this? reg exp or something else?

    The code;
    Code:
    var=my.test.file.23.45
    echo $(( ${var##*.} + 1 ))
    That returns '46', which is correct (i.e. 45+1) - What I need to understand is the var##*. piece. How is that saying 'go to the end of the string, the part after the '.', and return that'

  2. #2
    Join Date
    Jan 2008
    Location
    Manchester UK
    Beans
    13,616
    Distro
    Ubuntu

    Re: Bash: Please explain ${var##*.}

    Look at the bottom of this page, it explains it very well.

    http://mywiki.wooledge.org/BashGuide/Parameters

    In order to answer your question about what you should be searching for it's called parameter expansion.
    Last edited by nothingspecial; September 5th, 2011 at 11:04 AM.

  3. #3
    Join Date
    Apr 2011
    Beans
    30
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Bash: Please explain ${var##*.}

    Nice link, thanks for the reply!

  4. #4
    Join Date
    Jan 2008
    Location
    Manchester UK
    Beans
    13,616
    Distro
    Ubuntu

    Re: Bash: Please explain ${var##*.}

    No problem. Read the FAQs and bash pitfalls sections as well when you have time.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •