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

Re: bashing



On Sun, 2006-02-26 at 11:28 -0600, hbrhodes wrote:
> if i can tell the program TAR to put the date into something by typing 
> date '%Y %m%d'.tar, can i do the same with bash?  for instance if i make 
> a sh that makes a several tar files, i should be able to tell bash to 
> pipe (i think) a command that will keep the tar names without me having 
> to type them all in.
> tar cZf  date '%Y %m%d'_whatever.tar /home/user1
> get 2006 0224 whatever.tar
> get 2006 0225 whatever.tar
> get 2006 0226 whatever.tar
> and i want to make these files 'gz' without telling gzip to compress 
> each one individually or saying gzip -9 *.tar.  i was looking through 
> www.tldp.org, but the bash intro thing wasn't sinking in.
> has anyone had experience with telling bash to rename something, and how 
> is it done?

I'm having difficulty understanding what you want.

First off, you can put the output of _any_ command into a variable, and
then use it.  E.g.,

$ MYDATE=`date +%Y_%m%d`
$ command blah${MYDATE}.whatever

Secondly, if you're looking for loops based on files, that's the "find"
command.  E.g.,

  for myvar in `find . -mount`; do
    ...
  done

An alternative is to pipe the find out put to xargs ...

  find . -mount | xargs ...

Note that these do _not_ work if the filenames have spaces in them.  I
have _never_ successfully been able to use the "IFS" variable to do so.
Furthermore, bash 2.0x, 3.0s and other releases are _inconsistent_ on
handling such.  And the Advanced Bash Scripting Guide is _dead_wrong_ on
putting the output from find in quotes -- that's tcsh _not_ bash!

BTW, if you're looking for a sequence of dates, use the output from the
"seq" command.  You can even pass "-f %02g" to format to 2 digits with a
leading zero if its only 1 digit.

E.g., give me all days in February ...

  for i in `seq -f %02g 1 28`; do
    command file_02${i}.whatever
  done


-- 
Bryan J. Smith             Professional, technical annoyance
mailto:b.j.smith@ieee.org       http://thebs413.blogspot.com
------------------------------------------------------------
****** Speed doesn't kill.  Difference in speed does! ******



-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.