Help need with remove command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help need with remove command
# 8  
Old 03-18-2013
You do not need to put any of your commands into $( ) here.

I don't see much point nesting your if's 5-deep here, check for something and if it fails, quit then and there! Keeps things simple.

Code:
if [ -z "$INPUTDIR" ] # -z means, if string is blank.
then
        echo "inputdir not set"
        exit 1
fi

if [ ! -d "$INPUTDIR" ] # -d means, if a directory by that name exists.
then
        echo "inputdir not a directory"
        exit 1
fi

# Set $1=inputdir/file1, $2=inputdir/file2, ...
# If it finds nothing, it will become the literal string inputdir/file*.
# Check if $1 exists, if it didn't, it found nothing.
set -- ${INPUTDIR}/${PATTERNB}*

if [ ! -e "$1" ] # -e means, file or directory by that name exists.
then
         echo "Nothing found matching $PATTERNB"
         exit 1
fi

if ! rm "$@"
then
        echo "Couldn't remove $@"
        exit 1
fi

echo "Removed $@"
exit 0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can not remove file using rm command

I have two questions: the first is I have a line of code: printf "What is the id of the patient getting GJB2 analysis : "; read id that stores a user input in a variable $id in the python directory c:/Users/cmccabe/Desktop/Python27/$id.txt Using rm I get the error cannot remove ... (21 Replies)
Discussion started by: cmccabe
21 Replies

2. UNIX for Dummies Questions & Answers

cut or remove command

hi, I want to remove first word in all files where first and second word is seperated by comma. example: a file contains Apple,mango. i need only mango shoule be there in the file??? Apple, should be removed!!!!! can anyone help me out??? thanks in advance, Arun Manas:b: (2 Replies)
Discussion started by: arunmanas
2 Replies

3. Shell Programming and Scripting

simple remove command -ksh

KSH A simple remove command is not workin for me. The user has all the access and the return code after remove command is 0. But I am still able to find the file. I have the code as below. tmplog=/tmp/$fl_nm.$$ main () { --set of statments rm -fr $tmplog RC=$? } (2 Replies)
Discussion started by: tostay2003
2 Replies

4. AIX

Unable to remove files from rm command

I need to delete some files which are not getting removed not even from root user -rw-r----- 1 ptml tellin 0 Jul 26 19:23 temp.out1 -rw-r----- 1 ptml tellin 0 Jul 26 19:23 temp.out -rw-r----- 1 ptml tellin 2 Jul 26 19:23 prev -rw-r----- 1... (4 Replies)
Discussion started by: m_usmanayub
4 Replies

5. UNIX for Dummies Questions & Answers

Command to remove First and Last line from a File

I have a file from which the Header and the Trailer lines need to be removed. They are confirmed to be the first and the last lines in the file. I have tried a few commands, but not successful yet. It needs to be implemented urgently, hence any help is greatly appreciated. Raghu ----------... (1 Reply)
Discussion started by: ragz_82
1 Replies

6. UNIX for Dummies Questions & Answers

inverse remove command

Hi All, Is there an option for 'rm' to "remove everything but these files"? For instance if I have: a.txt <-- I just want to remove this one a_1.txt a_2.txt Is there an option ? for this: rm -? *_*.txt Thanks, ScKaSx (4 Replies)
Discussion started by: ScKaSx
4 Replies

7. UNIX for Dummies Questions & Answers

Find and remove command - can you tell me exactly what its doing?

find /app01/tomcat_local -name *jsp* -type f -exec rm -r {} \; I would assume the above is just deleting any *jsp* below the /app01/tomcat_local directory - is this correct as its seems to delete more than I expect.... (1 Reply)
Discussion started by: frustrated1
1 Replies

8. Shell Programming and Scripting

rm command not able to remove file

I have directory IXNPG7 under which i have seen file ads.c , ads.gif , ads.js and lots more with extension .html I tried to remove the Entire Directory with rm -Rf IXNPG7 but it is saying -- Directory Not empty can't remove Secondly i tried removing all the files first using rm *.*... (7 Replies)
Discussion started by: jambesh
7 Replies

9. UNIX for Dummies Questions & Answers

command to remove last record on file

Hi, First time on the forum. I have converted some files using the Unix to DOS command but need to strip off the last record that is generated from this conversion that contains just a ^Z. Is there any command that would accomplish this without having to do stream editing? (4 Replies)
Discussion started by: mheinen
4 Replies

10. UNIX for Dummies Questions & Answers

search and remove command

I want to run the 'locate' command and then remove what the command finds. My guess was, locate blahblah |rm -f but this does not work. Thanks! (3 Replies)
Discussion started by: jasonr
3 Replies
Login or Register to Ask a Question
dpkg-maintscript-helper(1)					    dpkg suite						dpkg-maintscript-helper(1)

NAME
dpkg-maintscript-helper - works around known dpkg limitations in maintainer scripts SYNOPSIS
dpkg-maintscript-helper command [parameters...] -- maint-script-parameters COMMANDS AND PARAMETERS
rm_conffile conffile [lastversion [package]] mv_conffile oldconffile newconffile [lastversion [package]] DESCRIPTION
This program is designed to be run within maintainer scripts to achieve some tasks that dpkg can't (yet) handle natively either because of design decisions or due to current limitations. Many of those tasks require coordinated actions from several maintainer scripts (preinst, postinst, prerm, postrm). To avoid mistakes the same call simply needs to be put in all scripts and the program will automatically adapt its behaviour based on the environment variable DPKG_MAINTSCRIPT_NAME and on the maintainer scripts arguments that you have to forward after a double dash. CONFFILE RELATED TASKS
When upgrading a package, dpkg will not automatically remove a conffile (a configuration file for which dpkg should preserve user changes) if it is not present in the newer version. There are two principal reasons for this; the first is that the conffile could've been dropped by accident and the next version could restore it, users wouldn't want their changes thrown away. The second is to allow packages to tran- sition files from a dpkg-maintained conffile to a file maintained by the package's maintainer scripts, usually with a tool like debconf or ucf. This means that if a package is intended to rename or remove a conffile, it must explicitly do so and dpkg-maintscript-helper can be used to implement graceful deletion and moving of conffiles within maintainer scripts. REMOVING A CONFFILE If a conffile is completely removed, it should be removed from disk, unless the user has modified it. If there are local modifications, they should be preserved. If the package upgrades aborts, the newly obsolete conffile should not disappear. All of this is implemented by putting the following shell snippet in the preinst, postinst and postrm maintainer scripts: dpkg-maintscript-helper rm_conffile conffile lastversion package -- "$@" conffile is the filename of the conffile to remove. lastversion is the last version of the package that contained the conffile (or the last version of the package that did not take care to remove the obsolete conffile if this was not immediately implemented). If lastver- sion is empty or omitted, then the operation is tried on every upgrade. package is the package name, it's optional as it will default to $DPKG_MAINTSCRIPT_PACKAGE (this variable is set by dpkg to the name of the package acted upon). All the parameters of the maintainer scripts have to be forwarded to the program after "--". Current implementation: in the preinst, it checks if the conffile was modified and renames it either to conffile.dpkg-remove (if not modi- fied) or to conffile.dpkg-backup (if modified). In the postinst, the latter file is renamed to conffile.dpkg-bak and kept for reference as it contains user modifications but the former will be removed. If the package upgrade aborts, the postrm reinstalls the original conffile. During purge, the postrm will also delete the .dpkg-bak file kept up to now. RENAMING A CONFFILE If a conffile is moved from one location to another, you need to make sure you move across any changes the user has made. This may seem a simple change to the preinst script at first, however that will result in the user being prompted by dpkg to approve the conffile edits even though they are not responsible of them. Graceful renaming can be implemented by putting the following shell snippet in the preinst, postinst and postrm maintainer scripts: dpkg-maintscript-helper mv_conffile oldconffile newconffile lastversion package -- "$@" oldconffile and newconffile are the old and new name of the conffile to rename. lastversion is the last version of the package that con- tained the conffile with the old name. If lastversion is empty or omitted, then the operation is tried on every upgrade (note: it's safer to give the version and have the operation tried only once). package is the package name, it's optional as it will default to $DPKG_MAINTSCRIPT_PACKAGE (this variable is set by dpkg to the name of the package acted upon). All the parameters of the maintainer scripts have to be forwarded to the program after "--". Current implementation: the preinst checks if the conffile has been modified, if yes it's left on place otherwise it's renamed to oldconf- file.dpkg-remove. On configuration, the postinst removes oldconffile.dpkg-remove and renames oldconffile to newconffile if oldconffile is still available. On abort-upgrade/abort-install, the postrm renames oldconffile.dpkg-remove back to oldconffile if required. INTEGRATION IN PACKAGES
Given that dpkg-maintscript-helper is used in the preinst, using it unconditionally requires a pre-dependency to ensure that the required version of dpkg has been unpacked before. The required version depends on the command used, for rm_conffile and mv_conffile it is 1.15.7.2: Pre-Depends: dpkg (>= 1.15.7.2) But in many cases the operation done by the program is not critical for the package, and instead of using a pre-dependency we can call the program only if we know that the required command is supported by the currently installed dpkg: if dpkg-maintscript-helper supports <command>; then dpkg-maintscript-helper <command> ... fi AUTHORS
Copyright (C) 2010 Raphael Hertzog Copyright (C) 2008 Joey Hess Copyright (C) 2007 Guillem Jover Copyright (C) 2005 Scott James Remnant This is free software; see the GNU General Public Licence version 2 or later for copying conditions. There is NO WARRANTY. Debian Project 2010-04-16 dpkg-maintscript-helper(1)