Unix Shell - My First Script

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > March 2004 > My First Script





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author My First Script
Understudy

2004-03-31, 8:40 am

Hi,

I recently wrote my first script. I got quite a bit of help from some people
I chat with on the IRC, and a lot of GIS. I am posting the link to the
script here so you can review it and tell me how it can be improved. I would
like to keep the line by line comments that explain what each line does it
helps me to remember why I put them there. There are also several lines I
have that work but I don't completely understand how. I was hoping you could
shed a bit of newbie enlightenment on them.
The script is at:
http://www.understudy.net/files/portbuild.txt
I wrote the script because I am basically lazy and didn't want to have to
type make && make install && rehash && make clean every time I installed a
port. I also want the script to remind me when I was rushing around and not
being careful of what I was doing and to be sure this is what I wanted to
do. So there is some biting echoes in the script. I did csh script for the
first one because it seems everyone can write a bash script. I wanted to be
different. By the way the script does work for me.

Sincerely,
Brendhan


NimDrauG

2004-03-31, 9:42 am

Understudy wrote:

> Hi,
>
> I recently wrote my first script. I got quite a bit of help from some
> people I chat with on the IRC, and a lot of GIS. I am posting the link to
> the script here so you can review it and tell me how it can be improved. I
> would like to keep the line by line comments that explain what each line
> does it helps me to remember why I put them there. There are also several
> lines I have that work but I don't completely understand how. I was hoping
> you could shed a bit of newbie enlightenment on them.
> The script is at:
> http://www.understudy.net/files/portbuild.txt
> I wrote the script because I am basically lazy and didn't want to have to
> type make && make install && rehash && make clean every time I installed a
> port. I also want the script to remind me when I was rushing around and
> not being careful of what I was doing and to be sure this is what I wanted
> to do. So there is some biting echoes in the script. I did csh script for
> the first one because it seems everyone can write a bash script. I wanted
> to be different. By the way the script does work for me.
>
> Sincerely,
> Brendhan


I always learnt that scripting in csh is a bad habit.
- http://frmb.org/csh_whynot.html

If you want to be different, why not use rc for scripting?
- http://www.star.le.ac.uk/~tjg/rc/
- http://www.cs.bell-labs.com/magic/man2html/1/rc
- http://www.star.le.ac.uk/~tjg/rc/misc/td

NimDrauG.
--
mail $(echo xaxrxjxaxnx. xgxrxoxexnxexmxexixjxexr@xexuxrxoxnxextx
.xnxlx | sed
's/x//g')
Understudy

2004-03-31, 11:37 am


"> I always learnt that scripting in csh is a bad habit.
> - http://frmb.org/csh_whynot.html
>
> If you want to be different, why not use rc for scripting?
> - http://www.star.le.ac.uk/~tjg/rc/
> - http://www.cs.bell-labs.com/magic/man2html/1/rc
> - http://www.star.le.ac.uk/~tjg/rc/misc/td
>
> NimDrauG.
> --
> mail $(echo xaxrxjxaxnx. xgxrxoxexnxexmxexixjxexr@xexuxrxoxnxextx
.xnxlx |

sed
> 's/x//g')


Well I also have it now in Bourne shell at :
http://www.understudy.net/files/portbuildsh.txt

I am going to also try to write it in Bash, Korn and Z.
Sincerely,
Brendhan


Ed Morton

2004-03-31, 3:40 pm



Understudy wrote:
> "> I always learnt that scripting in csh is a bad habit.


It is.
<snip>
> Well I also have it now in Bourne shell at :
> http://www.understudy.net/files/portbuildsh.txt


You should really post it here (I'd reommend you strip out the comments
first as they wouldn't be useful to most of the readers here) if you
want it critiqued, but anyway:

1) Use quotes around your file/dir names in case they contain white space.
2) Change your if-else (and enclosing loop) to a switch like:

until [ "$done" ]
do
case $response in
y*|Y* ) do "YES" stuff ;;
n*|N* ) do "NO" stuff ;;
* ) do else stuff
done="y" ;;
esac
done

3) You may want to work on your user feedback messages ;-).

Ed.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com