Skip to content

Commit

Permalink
Merge pull request #201 from mknos/unlink-cmd
Browse files Browse the repository at this point in the history
Add unlink command
  • Loading branch information
briandfoy authored Jul 13, 2023
2 parents 7d5d02b + 3688304 commit 9ef966a
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ bin/uname
bin/unexpand
bin/uniq
bin/units
bin/unlink
bin/unpar
bin/unshar
bin/uudecode
Expand Down
82 changes: 82 additions & 0 deletions bin/unlink
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/perl

=encoding utf8
=begin metadata
Name: unlink
Description: simpler than rm
Author: Michael Mikonos
License: artistic2
=end metadata
=cut

use strict;

use File::Basename qw(basename);
use Getopt::Std qw(getopts);

use constant EX_SUCCESS => 0;
use constant EX_FAILURE => 1;

my $Program = basename($0);

unless (getopts('')) {
warn "usage: $Program FILE\n";
exit EX_FAILURE;
}
unless (@ARGV) {
warn "$Program: missing operand\n";
exit EX_FAILURE;
}
my $file = shift;
if (@ARGV) {
warn "$Program: extra operand: '$ARGV[0]'\n";
exit EX_FAILURE;
}
if (-d $file) {
warn "$Program: cannot unlink '$file': is a directory\n";
exit EX_FAILURE;
}
unless (unlink $file) {
warn "$Program: cannot unlink '$file': $!\n";
exit EX_FAILURE;
}
exit EX_SUCCESS;

__END__
=head1 NAME
unlink - remove a file
=head1 SYNOPSIS
unlink [--] file
=head1 DESCRIPTION
A single file is removed by calling the unlink function.
If the argument is a symbolic link, the link is removed instead of the file it refers to.
It is not possible to remove a directory with this program.
=head2 OPTIONS
None.
=head1 EXIT STATUS
This command exits 0 if the named file was removed successfully.
If an error occurs, unlink exits with a value >0.
=head1 AUTHOR
Written by Michael Mikonos.
=head1 COPYRIGHT
Copyright (c) 2023 Michael Mikonos.
This code is licensed under the Artistic License 2.

0 comments on commit 9ef966a

Please sign in to comment.