Results 1 to 3 of 3

Thread: Please explain why this bash string function fails

  1. #1
    Join Date
    Jan 2011
    Beans
    274

    Please explain why this bash string function fails

    Ubuntu 12.04.1 LTS
    GNU bash, version 4.2.24(1)-release (x86_64-pc-linux-gnu)


    I'm looking to replace '/' with '-'

    why is output 11-/11-/2012 and not 11-11-2012?


    #!/bin/bash
    a=11/11/2012
    b=${a//\//-/}
    echo $a $b
    exit

    OUTPUT:
    11/11/2012 11-/11-/2012

  2. #2
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Please explain why this bash string function fails

    Code:
    $ a=11/11/2012
    $ echo ${a//\//-}
    11-11-2012
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  3. #3
    Join Date
    Jan 2011
    Beans
    274

    Re: Please explain why this bash string function fails

    Quote Originally Posted by Vaphell View Post
    Code:
    $ a=11/11/2012
    $ echo ${a//\//-}
    11-11-2012
    Thank you. This works perfectly.

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
  •