Fixing fc -s in dash

For the moment, fc -s is hilariously broken in dash upstream. This is one of the most useful shell commands ever, so here is a stupid simple replacment function for you to source in your $ENV:

fcs () {
    # If = in first arg, old=new substitution from first occurrence.
    old="${1%%=*}"
    if [ ${#old} -lt ${#1} ]; then
        new="${1#*=}"
        eval $( fc -ln ${2:-"-1"} ${2:-"-1"} | sed "s/$old/$new/" )
    else
        eval $( fc -ln ${1:-"-1"} ${1:-"-1"} )
    fi
}

This works for both numbered and string search references to history. Hardly a masterpiece, but it does what it's supposed to do, unlike the builtin.

A couple of notes. If you are using Debian or Ubuntu, although dash is the default /bin/sh, it is built without libedit by default, and therefore does not have fc, nor any other interactive features. Additionally, the behaviour of fc is not very consistent across shells, so do not expect this to work on e.g. bash - however, hopefully those shells do not require workarounds in the first place.