[plug] script error
Craig Ringer
craig at postnewspapers.com.au
Thu Jan 12 17:02:56 WST 2006
Mr E_T wrote:
> On Thursday 12 January 2006 15:40, Jon Miller wrote:
>
>>Any idea how to append 1 file to another? using cat file1 >> file2 does not work in a script.
>>
>
> also to get the perm right use
> chmod --reference=${tmail}/{$1} ${cmail}/${1}
> chown --reference=${tmail}/{$1} ${cmail}/${1}
AFAIK permissions are only affected by the >> redirect operator if the
second file must be created. In that case, I think the file is created
according to the umask, so you would need to change the permissions if
you need to override the defaults.
Usually, you're better off setting the umask at the beginning of the
script. Please don't just write a hard-coded umask unless you REALLY
know you need it; just set or clear the bits you absolutely need to
control using the `&' and `|' binary operators.
I really hate it when programmers blindly set the `umask'. Not that I'm
looking at you, Mozilla project, or anything...
> cat $omail/$1 > $cmail/$1
> cat $tmail/$1 >> $cmail/$1
>
> Notice the first cat is a single > this creates or zreos the file first.
Strictly, it truncates it, creating it if it does not exist. It doesn't
as such zero anything. If I have a 1MB file "spam" and run:
echo eggs > spam
this truncates `spam' to 5 bytes (4 bytes, plus newline because I didn't
use `echo -n'). If `spam' didn't exist, it would've been created.
See:
$ info '(bash.info.gz)Redirections'
for details on this, and a lot of other important things. Another really
good bash info page to read is:
$ info '(bash.info.gz)Shell Parameter Expansion'
This will teach you a LOT about smarter ways to manipulate the data you
work with. You'll find it much less necessary to break out to `sed',
`awk', or edit pipelines with `cut' and friends.
The bash manual isn't easy to find things in, can be rather dense, and
isn't the best organized ... but it is very complete. Please don't
ignore it.
--
Craig Ringer
More information about the plug
mailing list