The Lumber Room

"Consign them to dust and damp by way of preserving them"

Bash script

leave a comment »

Relocate, using lns from Simon Tatham’s site.

function crude_dirname()
{
    echo "${1%/*}" # everything before last '/'
}

function crude_basename()
{
    echo "${1##*/}" # everything after last '/'
}

function relocate
{
    a=$1
    #Strip trailing slash, if there is one
    A="${a%/}"
    a=$A

    a_act=$(crude_basename $a)
    b=$2
    b_dir=$(crude_dirname $b)
    b_act=$(crude_basename $b)

    echo "mv $a $b"
    if [ -z $b_act ] #If the string b_act has length 0
        then
        loc="$b_dir/$a_act"
    else
        loc="$b"
    fi
    echo "lns $loc $a"


    echo "Fine?"
    read x
    if [ $x == "y" ]
        then
        mv "$a" "$b"
        lns "$loc" "$a"
    fi
}

Written by S

Mon, 2006-10-16 at 21:42:12

Posted in Uncategorized

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s