NYCPHP Meetup

NYPHP.org

[nycphp-talk] [OT] Calling All Shell Scripters!

Nasir Zubair nasir81 at gmail.com
Fri Oct 8 14:55:56 EDT 2004


Hi,

Try the following:

#SYNTAX: delete_tar $folderPath $origFolderName $today
delete_tar()
{
 echo "Are you sure you want to delete TAR file '${1}/${2}_${3}.tar.gz'?
(Y/N Enter = N) "; 
read isOKDelete

if [ "${isOKDelete}" = "Y" -o "${isOKDelete}" = "y" ]; then
 rm ${1}/${2}_${3}.tar.gz
fi
}

What I changed:

- in the test statement, variables are surrounded by double quotes.
That is because if the variable is empty (user pressed Enter for N),
it will not be passed onto the test statement. Surrounding it with
quotes will make sure that if the variable is empty, an empty string
is passed on to the test.

- [[ ... ]]   :  The only shell I've seen using this syntax for test
is KSH. So you should have specified which shell you are using.



On Fri, 08 Oct 2004 11:04:14 -0400, Phillip Powell
<phillip.powell at adnet-sys.com> wrote:
> I know you know Shell Script, you're all LAMP demigods out there, so I'm
> not surprised you dream in Shell Script as well.  In any case, I need
> some help with a very simple function I wrote for a command-line
> PHP-based application program migrator I wrote:
> 
> # SYNTAX: delete_tar $folderPath $origFolderName $today
> delete_tar()
> {
> echo "Are you sure you want to delete TAR file ""$1/${2}_${3}.tar.gz""?
> (Y/N Enter = N) "; read isOKDelete
> if [ $isOKDelete = "Y" -o $isOKDelete = "y" ]; then
>  rm $1/${2}_${3}.tar.gz
> fi
> }
> 
> ------------------------------
> --------------------------------------------------
> 
> I  continually get the "too many arguments" error on the "if" line if I
> do not enter either "Y" or "y".
> 
> [Quote]
> /home/me/scripts/icatalog_unpackager.sh: [: too many arguments
> [me at www me]$
> [/Quote]
> 
> As dumb as this is going to sound, how must I do this correctly?  I have
> already gone to Linux Shell Script tutorials and apparently am not
> grasping this.
> 
> Thanx
> Phil
> 
> --
> ---------------------------------------------------------------------------------
> Phil Powell
> Multimedia Programmer
> BPX Technologies, Inc.
> #: (703) 709-7218 x107
> Fax: (703) 709-7219
> 
> _______________________________________________
> New York PHP Talk
> Supporting AMP Technology (Apache/MySQL/PHP)
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.newyorkphp.org
>



More information about the talk mailing list