[plug] Bash scripting error with functions

Onno Benschop onno at itmaze.com.au
Sun Jun 12 20:08:38 WST 2005


Can someone explain to me why the following script returns:

    xargs: make_file_link: No such file or directory


The script itself:

#!/bin/bash

source_dir="$1"
target_dir="$2"

make_link () {
    local source="$1"
    local target="$2"
    ln -s "${source}" "${target}"
}

get_md5_hash () {
    echo `md5sum "$1" | cut -f1`
}

make_file_link () {
    local link_name=`get_md5_hash "$1"`
    make_link "$1" "${target_dir}/${link_name}"
}

find "${source_dir}" -type f -print0 | xargs -0 -n1 make_file_link


The purpose of the script is to find all the files in a directory tree, 
make a symbolic link to each file using the md5 of the file as the name 
of the symbolic link.

The way you need to call it is:

    script_name {source_dir} {target_dir}


There is no error checking, but it shouldn't be able to actually break 
anything on your computer, but please don't run it unless you understand 
what it's doing, because if you break it, you get to keep both parts.

-- 
Onno Benschop

Connected via Optus B3 at S34°45'36.5" - E139°00'08.7" (Mount Pleasant, SA)
--
()/)/)()        ..ASCII for Onno..
|>>?            ..EBCDIC for Onno..
--- -. -. ---   ..Morse for Onno..

Proudly supported by Skipper Trucks, Highway1, Concept AV, Sony Central, Dalcon
ITmaze   -   ABN: 56 178 057 063   -  ph: 04 1219 8888   -   onno at itmaze.com.au





More information about the plug mailing list