dylan

Results 130 comments of dylan

Fixed. ```sh dirname() { # Usage: dirname "path" dir=${1%%/} [[ $dir ]] || dir=// [[ $dir == */* ]] || dir=. printf '%s\n' "${dir%/*}" } ```

Try this one: ```sh dirname() { # Usage: dirname "path" dir=${1%%/} dir=${dir%/*} [[ $1 == */* ]] || dir=. printf '%s\n' "${dir:-/}" } ``` It passes my ever growing list...

Here we go again: ```sh dirname() { # Usage: dirname "path" dir=${1%%/} [[ "${dir##*/*}" ]] && dir=. dir=${dir%/*} printf '%s\n' "${dir:-/}" } ```

I'm testing against `busybox` `dirname` as I don't use `glibc`/GNU `coreutils`. I'm not sure if `busybox` `dirname` is **more** POSIX compliant or not.

Here's an implementation of the algorithm described in the standard: ```sh dirname() { # Usage: dirname "path" local tmp=${1:-.} [[ $tmp != *[!/]* ]] && { printf '/\n' return }...

Here's another implementation which also passes all of my tests. It's also effectively the same algorithm as above. ```sh dirname() { # Usage: dirname "path" local tmp=${1:-.} tmp=${tmp%%"${tmp##*[!/]}"} [[ ${tmp##*/*}...

I'll push the direct implementation to the bible. :+1: Regardless of whether or not it is 100% compatible with the standard, this version is a lot "more" compatible with it....

@pjeby, both `basename` and `dirname` in the bible match their external utilities 1:1 now. If you can reproduce cases in which they don't, I'd love to know.

Bonus! The entire function inside an arithmetic block `(( ))`. This really starts to look like another language entirely! The coolest part: ``` -> time rgb2hsl 186 100 53 real...

Dummy comment for image hosting. ![oie_transparent](https://user-images.githubusercontent.com/6799467/65238742-e0ba4c80-dacc-11e9-9c2a-3dd20a6f138d.png)