[plug] Bash scripting error with functions

Quintin Lette qlette at gmail.com
Sun Jun 12 20:14:04 WST 2005


aren't you supposed to use the word function before the function itself?

ie:

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

this may not be the whole problem, but afaict it should work.


On 6/12/05, Onno Benschop <onno at itmaze.com.au> wrote:
> 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
> 
> 
> _______________________________________________
> PLUG discussion list: plug at plug.org.au
> http://www.plug.org.au/mailman/listinfo/plug
> Committee e-mail: committee at plug.linux.org.au
>



More information about the plug mailing list