Scripting (was Re: Cron job for backup)
der.hans
PLUGd at LuftHans.com
Tue Dec 11 13:15:59 MST 2007
Am 11. Dec, 2007 schwätzte Matrix Mole so:
> der.hans wrote:
>> Am 11. Dec, 2007 schwätzte Patrick Fleming, EA so:
>>
>>> BACKUPDIRNAME=`date +Y%m%d%` #these are backtics -
>>
>> Use $( ) format for bash and ksh scripts :).
>>
>> BACKUPDIRNAME=$( date +Y%m%d% )
>
>
> I've heard this a couple times now, but never had anyone explain why the
> $( ) format is preferred over the back quote in bash scripts. I have
> begun to try remembering to use the $( ) format in my scripts now, but I
> still find myself using back quotes quite often. So why is back quotes
> not considered a good method of shelling out a command to the system?
I use it and teach it because it's easier to read. It's also nestable.
locate mp3
ls $( locate mp3 ) 2>/dev/null # makes sure they still exist
for i in $( ls $( locate mp3 ) 2>/dev/null ); do mp32ogg $i && rm $i; done
A pretty bogus example that could be done in better ways, but it shows the
nested use of subshells :).
ciao,
der.hans
--
# https://www.LuftHans.com/ http://www.CiscoLearning.org/
# Knowledge is useless unless it's shared. - der.hans
More information about the PLUG-discuss
mailing list