Sunday, July 24, 2011

Basename function processing without basename binary installed

OK, so Im going to start posting some howto pages to this blog.

starting with a bash scripting case statement to decide script function based on "basename" (or the name of the file running as the script) without the "basename" binary installed. This way you can create many links to the same script, and make the that script do many different things determined by the link name it is being called as. Then you just need to make sure these links to the script are in a directory somewhere within your $PATH.

example:
case $(echo ${0##*/} |cut -d '/' -f $(echo ${0##*/} |wc -w)) in
    scriptlinkname1)
        echo "doing the function scriptlinkname1"
        ;;
    *)
        echo "did not define that links function yet"
        ;;
esac


hope you find this helpful.

No comments:

Post a Comment