Sponsored Content
Full Discussion: script similar to rm utility
Homework and Emergencies Homework & Coursework Questions script similar to rm utility Post 302475901 by vbe on Tuesday 30th of November 2010 09:15:40 AM
Old 11-30-2010
Code:
 if [ ! -d ~/.saferm ]  # dont forget the space after [ , and before ]

Your >&2 although correct ( where do you usually display the result of an echo?) is superflu IMHO (makes sence if you were to log errors somewhere...)

Be more respectfull in your indentation (2 or 3 char? once decided, stck to it!)
e.g.
Code:
if [ $# != 1 ]
then
   echo "Usage: saferm  -l  (or a filename)" # >&2
   exit 1
fi

if [ ! -d ~/.saferm ]
then
   mkdir ~/.saferm
fi

if [ "$1" = "-l" ]
then
   ls -l ~/.saferm
else
   mv $1 ~/.saferm
fi

Notice the third test, I removed a = sign, it will not work like that in ksh and you didnt mention what shell you were using...

---------- Post updated at 15:15 ---------- Previous update was at 15:01 ----------

And you didnt test if $1 existed, you risk to see you shell complain...

So your final script should look like: (I changed test syntax so you see there are other ways possible...)
Code:
if [ $# != 1 ]
then
   echo "Usage: saferm  -l  (or a filename)" # >&2
   exit 1
fi

if [ ! -d ~/.saferm ]
then
   mkdir ~/.saferm
fi

if [ "$1" = "-l" ]
then
   ls -l ~/.saferm
else
   if test -f "$1"; then
      mv $1 ~/.saferm
   else
     echo "$1 inexistant file "
   fi
fi

All the best
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

cdrdao utility script

friends, i love ya... i wrote a script to automate using cdrdao to burn an audio cd from mp3 files, using the great tutorial at http://tldp.org/HOWTO/MP3-CD-Burning/index.html (check out the site, i believe that it's very well-written). i messed around with it and got to a place where i felt... (2 Replies)
Discussion started by: snwright
2 Replies

2. Shell Programming and Scripting

sort utility in script ?

Hi friends, I want to use sort command in script. I used the following syntax in my scipt, sort -t '|' +3 tempcdrext4.cdr > temp.mocdr It give me a error " Input file specified two times." but this command work fine in the prompt without any problem. Can sombody please tell me who... (2 Replies)
Discussion started by: maheshsri
2 Replies

3. UNIX for Dummies Questions & Answers

Need help on SCRIPT(1M) utility

Hi All, I need to do a lot of manual entries at shell prompt. So to collect the logs(each command fired in that session, i use "SCRIPT(1) : make typescript of terminal session" this is kool,but the problem here is that it saves the linefeed, and backspaces along with the commands in the log... (1 Reply)
Discussion started by: amit4g
1 Replies

4. Shell Programming and Scripting

copy similar files only both at different locations using script.

Hello, Here is the situation.............. # pwd /opt/123 # cat index.txt abc-monitor/homedir/public_html/index.php abc-monitor/homedir/public_html/test/index.php abc-monitor/homedir/public_html/test1/index.php # cp index.txt index.home # cat /root/x (1 Reply)
Discussion started by: fed.linuxgossip
1 Replies

5. Shell Programming and Scripting

Help on how to call a utility from script

Hi, I am new to shell scripting (sh) I need a script which will call a utility & once u call it.It will ask for inputs on the screen.These inputs it needs to get or read from a txt file. for e.g #! /bin/sh while read line do echo $line done txt file will have test 01/01/2008 ... (3 Replies)
Discussion started by: innocent
3 Replies

6. Shell Programming and Scripting

Writing a Utility Script

Hi All ,, I have couple of shell scripts .. I am trying to build a Utility script which would call each script example :: ======== 1) uni.sh 2) uni2.sh 3)uni3.sh when i run the Util script it will come as a menu ,, once i press 1 it will call the first shell script and runs it ..... (10 Replies)
Discussion started by: raghav1982
10 Replies

7. Shell Programming and Scripting

I need help to run this utility from a shell script

I need some help to run this executable from within a shell script. The Script is run the following way at the command prompt. $rateupd Main Menu --Standard Output ----------- --Standard Output 1. - Update Rate --Standard Output 2. - Exit. --Standard Output Enter Selection: 1 --User... (5 Replies)
Discussion started by: rajeeb_d
5 Replies

8. Shell Programming and Scripting

shell script similar to the command HEAD

hello please if anyone can help me make a shell script similar to the command HEAD and TAIL THANKS (3 Replies)
Discussion started by: BELLA86
3 Replies

9. Shell Programming and Scripting

Shell script matching similar records

hello all, I have requirement to identify similar records matching about 80% to 90%.I have to black list customers with multiple accounts. The data is in the Oracle Database, but is there any way I can get the data into flat file and compare the strings and fetch similar matching records? ... (2 Replies)
Discussion started by: kashik786
2 Replies

10. Shell Programming and Scripting

Isolate text with sed or similar utility

All, I'm getting a list like the following and I'd like to kill each PID in turn. pid (17797) pid (21748) pid (21754) pid (21704) pid (2199) pid (2159) pid (17809) pid (21769) pid (21778) pid (21715) ... (3 Replies)
Discussion started by: ejianu
3 Replies
NDISGEN(8)						    BSD System Manager's Manual 						NDISGEN(8)

NAME
ndisgen -- generate a FreeBSD driver module from a Windows(R) NDIS driver distribution SYNOPSIS
ndisgen [/path/to/INF /path/to/SYS] DESCRIPTION
The ndisgen script uses the ndiscvt(8) utility and other tools to generate a FreeBSD loadable driver module and a static ELF object module from a Windows(R) NDIS driver, for use with the ndis(4) compatibility module. The ndisgen script is interactive and contains its own help section. Unless the paths to both files are supplied on the command line, the script will prompt the user for the .INF and .SYS files needed to generate the FreeBSD driver module. The script will also prompt for any firmware or other external files needed. SEE ALSO
ld(1), objcopy(1), ndis(4), kldload(8), ndiscvt(8) HISTORY
The ndisgen utility first appeared in FreeBSD 6.0. AUTHORS
The ndisgen utility was written by Bill Paul <wpaul@windriver.com>. BSD
April 24, 2005 BSD
All times are GMT -4. The time now is 08:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy