[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Edlug Archive Mar 2007 ]

Re: [edlug] Shell scripts



On Tue, 2007-03-27 at 15:48 +0100, Rodti MacLeary wrote:
> From: David Hodgson
>  
> > For parameters, just do:
> > 
> > #!/bin/ksh
> > 
> > blah=$1
> > 
> > echo $blah
> > 
> > So, you would run yourscript.sh imaparameter
> 
> Okay, I think I'm just about there, but I still have two concerns I can't
> quite find the answer to in these FAQs.  I'm sure they'll be in there
> somewhere, it's just that I don't see them!
> 
> In the following examples parameter $1 would be in the format domain.tld
>  
> 1) Can I use a parameter in a path without any added syntax or special
> characters?  For example:
> 
>      mkdir /var/www/$1
> 
yes, you only need to be careful when you have a variable
foo=something
mkdir /var/www/${foo}bar
will expand to
mkdir /var/www/somethingbar

> 2) If I echo a series of strings to a file, will each one be appended on a
> new line, or will they overwrite each other?  Example:
> 
>      echo "<VirtualHost *>" > /etc/apache/$1
>      echo "     ServerName www./"$1/"" > /etc/apache/$1
>      echo "     DocumentRoot /var/www//"$1/"" > /etc/apache/$1
>      echo "</VirtualHost>"
> 
not quite you need to append to the file
a single > will always create a new file thus gobbling your existing
file. to append to the end use >>
     echo "<VirtualHost *>" > /etc/apache/$1
     echo "     ServerName www./"$1/"" >> /etc/apache/$1
     echo "     DocumentRoot /var/www//"$1/"" >> /etc/apache/$1
     echo "</VirtualHost>" >> /etc/apache/$1

magi


-
----------------------------------------------------------------------
You can find the EdLUG mailing list FAQ list at:
http://www.edlug.org.uk/list_faq.html



This archive is kept by wibble+RM@xxx.xxx.xxx
Morpheux
HomePage