Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2007
    Posts
    2

    Unanswered: meaning of arguments

    ${0##*/}
    ${0%/*}

    What these 2 lines do?

  2. #2
    Join Date
    Apr 2011
    Posts
    34
    Bash Reference Manual

    Respectively something like...
    ${0##*/}
    From parameter 0, remove as many character as possible (*) followed by character / starting from the beginning. (One # would be remove as little as possible)

    ${0%/*}
    From parameter 0, remove as little as possible matching / followed by any characters (*) from the end.

  3. #3
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Quote Originally Posted by mariostg View Post
    ${0##*/}
    From parameter 0, remove as many character as possible (*) followed by character / starting from the beginning. (One # would be remove as little as possible)

    ${0%/*}
    From parameter 0, remove as little as possible matching / followed by any characters (*) from the end.
    ...which is more or less equivalent to $(basename $0) and $(dirname $0), if I'm not mistaken.
    ---
    "It does not work" is not a valid problem statement.

  4. #4
    Join Date
    Apr 2011
    Posts
    34
    Pretty close

    marst@redstar(17:37 Friday 06 - September 2013)
    [~]
    >>>cat extract.sh
    #!/bin/sh
    echo ${1##*/}
    echo ${1%/*}
    echo $(basename $1)
    echo $(dirname $1)
    marst@redstar(17:37 Friday 06 - September 2013)
    [~]
    >>>./extract.sh /home/marst/programming/cpp
    cpp
    /home/marst/programming
    cpp
    /home/marst/programming
    marst@redstar(17:37 Friday 06 - September 2013)
    [~]
    >>>./extract.sh /home/marst/programming/cpp/

    /home/marst/programming/cpp
    cpp
    /home/marst/programming
    marst@redstar(17:37 Friday 06 - September 2013)
    [~]
    >>>

Posting Permissions

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