[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: Re: Help with a bash script please



In <[🔎] 20110114120047.GA7849@hysteria.proulx.com>, Bob Proulx wrote:
>Adrian Levi wrote:
>> zparameters="a -mhe=on -pd1ckhead -t7z -m0=lzma -mx=9 -mfb=64 -md=32m
>> -ms=on -si" zfilename="Daily Backup - $(date +"%a %h %H%M
>> %d-%m-%Y").$backuplevel.tar.7z"
>
>Yuck!  Look at all of those spaces in the filename!  :-)
>(Recalling all of the discussion over the past couple of days
>concerning whitespace in filenames and the problems that it causes.)

Whitespace in filenames does not cause problems.  Bad scripts (or programs) 
that don't pay attention to the characters allowed in their datatypes cause 
problems.

SQL-Injection attacks have the same cause.  It's single-quote and double-quote 
instead of whitespace, but it is the same cause.

XSS attacks sometimes have the same cuase.  It's a mutli-character sequence 
instead of whitespace, but it is the same cause.

>Do you really need spaces in the filename?  (Editorial remark: Unix
>users always avoid putting whitespace in filenames because they are a
>pain.)

I use spaces in filenames all the time, but I understand the sentiment.  If 
you don't know how your shell works it can be frustrating to deal with white 
space in file names.  Even if you do, command-lines that deal with files whose 
names contain white space are a bit longer and require more hand-motion to 
type.

>You can quote the filenames like this:
>
>  tar $tarparameters "$backuppath" | 7z $zparameters "$zfilename"

# backuppath need to be word split (it is two paths) before getting to tar
tar $tarparameters $backuppath | 7z $zparameters "$zfilename"

--8<-- END SCRIPT --8<-- CUT HERE -- 8<--

In general, a variable will either have contents that are mean to be word 
split by the shell, in which case it should be used without surrounding 
double-quotes but cannot be used for passing arguments containing IFS to 
commands OR have contents that are NOT mean to be word split by the shell, in 
which case it should be used with double-quotes surrounding it each time.

The environment variable IFS is used for doing word splitting.  If it unset, 
then consecutive runs of white space are delimiters.  However, it can be set 
to other combinations (HASH, COMMA, and AT-SIGN are common to add) and will 
affect how word splitting is done on not-quoted expansions.  In general, you 
should avoid not-quoted expansions where possible, but strictly conforming to 
the POSIX shell command language can make this difficult.  Beyond the 
standard, many shells can handle shell variables of array types and careful 
use of such types should allow all use of not-quotes expansions to be 
eliminated.
-- 
Boyd Stephen Smith Jr.                   ,= ,-_-. =.
bss@iguanasuicide.net                   ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy         `-'(. .)`-'
http://iguanasuicide.net/                    \_/

Attachment: signature.asc
Description: This is a digitally signed message part.


Reply to: