Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: string overwrites string when echoed



Peter Stephenson wrote:

> Replacing $reply with ${reply%%$'\r'} would
> do the trick.
>
> There may be something you can do with stty,
> but that's a bit out of the scope of the
> shell (or indeed sanity :-().

Ha!

Yes, it works. Thank you!

Feel free to elaborate on ${reply%%$'\r'}.
What does it do? Remove the last char of the
string if it matches the char given? I take it
the $ is because of the special char single
quotes. I get the same result with only one %
by the way.

Does this look good?

url-exists () {
    local url=$1
    curl -s -I $url | head -n 1 | cut -d\  -f2,3,4
}

urls-exist () {
    local -a urls
    urls=($@)

    local pad_max=$(echo "404 Not Found" | wc -m)

    local reply
    for u in $urls; do
        reply=$(url-exists $u)
        echo ${(r:$pad_max:: :)reply%%$'\r'} $u
    done
}
alias url=urls-exist

-- 
underground experts united
http://user.it.uu.se/~embe8573



Messages sorted by: Reverse Date, Date, Thread, Author