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
aptsh(1)						      General Commands Manual							  aptsh(1)

NAME
Aptsh - interactive APT shell SYNOPSIS
aptsh {install pkg | remove pkg | update | ... } [-?, --help] [-c, --config-file configuration_file ] [-s, --storing] [-v, --version] [-x, --execute aptsh_command ] DESCRIPTION
Aptsh is a tool which makes using APT much easier. It gives you an interactive shell with all those sweet features like tab-completion (which you can use to complete name of a package), simpler access to apt commands and easier package searching (ls, rls). Although it's not necessary, it just tries to make life easier. Other way of using Aptsh is using it as a normal command-line tool, a replacement for apt-* commands. USAGE
We'll try to do some ordinary administration tasks - install/remove/search few packages. As a root, type 'aptsh' and press return. Then type 'ins', and press Tab - 'ins' should change into 'install' followed by a whitespace. Now write down 'kde', and press Tab twice - if you're using Debian or other large distro, it should ask you whether you want to see all packages which begin with 'kde'. As you should have noticed - it works exactly like a good shell. You can also play with 'remove' - then aptsh will prompt only installed packages. And remember, that you can pipe results of commands (ie. dump | grep ^Package | cut -d -f 2 | grep ^kde ). You can execute a normal shell command by preceding it with ".". COMMANDS
Aptsh commands: dump-cfg Dump all aptsh options. dpkg Query dpkg. ls Search for packages by matching names to a wildcard. Remember that in some enviroments you have to put the expression between " " or preced special chars with . rls Search for packages by matching names to a regular expression. Read note about special chars above! whatis Display a short description of a package. whichpkg Find the package that supplies the given command or file. listfiles List all files owned by a package. news Obtain the latest news about the package from Debian servers changelog Retrieve latest changelog for the package from Debian servers toupgrade List packages with newer versions available for upgrading ` Change mode. queue-commit Commit stored commands. User answers to all prompts. queue-commit-say Commit commands kept in command queue, automatically answering to all prompts. It should be followed by the answer, if not, it answers (then usually program's behaviour is default). Proper usage of commit-say would be "commit-say y" - then Aptsh answers 'y' to all prompts. queue Display currently stored commands. queue-remove Remove stored commands from list. It should be followed by list or section of numbers of items to remove. Proper usage of this command would be: "commit-remove 1 3 10-15 21" - it will remove items numbered as 1, 3, 10, 11, 12, 13, 14, 15, 21. You can use alias 'last' which refers to the last item. queue-clear Clear list of stored commands orphans Find orphaned libraries on your system. orphans-all Find all orphaned packages on your system, not only libraries. It's output is other than the orphans' one - it's splitted into two columns, first one contains packages' Section, second Name. help Executes 'man aptsh', or displays short info about commands (if any were given as arguments). help-howto Displays HOWTO. You can pipe it to a browser ("more" or "less") or grep it. quit Erm... quit? :) apt-get querying commands (see man apt-get): install update upgrade dselect-upgrade dist-upgrade remove purge (same as remove --purge ) source build-dep check clean autoclean apt-cache querying commands (see man apt-cache): show dump add showpkg stats showsrc dumpavail unmet search depends rdepends pkgnames dotty policy madison AUTHOR
Marcin Wrochniak (wrochniak@gmail.com) version 0.0.6 20 Mar 2005 aptsh(1)