NAME
Fink::Command - emulate common shell commands in Perl
SYNOPSIS
use Fink::Command ':ALL';
mv @src, $dest; cp @src, $dest; my $text = cat $file; my @text = cat $file;
mkdir_p @dirs; rm_rf @dirs; rm_f @files;
touch @files;
chowname $user, @files;
symlink_f $src, $dest;
DESCRIPTION
Its a common tempation to write something like this:
execute("rm -rf $dir");
Instead of relying on shell utilities, we can do this inside Perl. This module provides a set of Perl functions emulating common shell utilities.
Functions
No functions are exported by default, they are all optional. You can get all of them with
use Fink::Command ':ALL';
Unless noted otherwise, functions set $! and return false on failure.
- mv
mv $src, $dest; mv @srcs, $destdir;
Like
mv
. - cp
cp $src, $dest; cp @srcs, $destdir;
Like
cp
. - cat
my $text = cat $file; my @text = cat $file;
Reads a file returning all the text in one lump or as a list of lines depending on context.
Returns undef on error, even in list context.
- mkdir_p
mkdir_p @dirs;
Like
mkdir -p
.Due to an implementation quirk, $! is not set on failure.
- rm_rf
rm_rf @dirs;
Like
rm -rf
- rm_f
rm_f @files;
Like
rm -f
- touch
touch @files;
Like
touch
. - chowname
chowname $user, @files; chowname "$user:$group", @files; chowname ":$group", @files;
Like
chowname
but the user/group specification is a bit simpler. Dot is not supported as a seperator. - symlink_f
symlink_f $src, $dest;
Like
ln -sf
. Currently requires the full filename for $dest (not just target directory. - du_sk
du_sk @dirs;
Like
du -sk
, though slower.On success returns the disk usage of @dirs in kilobytes. This is not the sum of file-sizes, rather the total size of the blocks used. Thus it can change on a filesystem with support for sparse files, or an OS with a different block size.
On failure returns "Error: <description>".
- _expand
my @expanded_paths = _expand(@paths);
Expands a list of filepaths like the shell would.
SEE ALSO
This module is inspired by ExtUtils::Command