removing characters from variable?
Hello,
I have the following script that I'm trying to use to backup specific directories on my box to my USB drive: Code:
for dir in /etc /var /home /usr/local /opt Resulting in several .cpio files (or one large one, I'm open to change here) with a filename of "backup.<directoryname>.<timestamp>.cpio . Now obviously this doesn't work because the variable $dir has /'s in it, making getting a nice error from cpio: Code:
cpio: /mnt/USBDrive/backup./etc.02_23_2009_22_02_08.cpio: No such file or directory Anyone have any ideas/suggestions to how I can get this working? Please be gentle, Ive been using linux for about 2 years now and LOVE it, but I'm still green about a few things!! This site has helped me a TON in the past, and I'd never actually had a need to post anything myself, until now. :) Thanks in advance!! |
|
Thanks for the reply David!
Quote:
Code:
for dir in /etc /var /home /usr/local /opt /etc /var /home /usr/local /opt Any further suggestions? Thanks again! |
Hmm. It works perfectly for me. Are you not using bash perchance?
You could try something like this then: Code:
for dir in /etc /var /home /usr/local /opt |
Thanks again!
Ah, that last one worked! I'm using bash: Code:
[/mnt/USBDrive]> echo $SHELL Code:
for dir in /etc /var /home /usr/local /opt I'm just getting into understanding awk and sed. Do you have any suggestions for some good online references that could help with comprehension of each? Thank you so much! :) --h87 |
Quote:
Code:
find /etc /var/ home /usr/local /opt -type d ...... |
Good to see it's working. But I'm still puzzled as to why the parameter substitution didn't work for you. I copied your test script exactly and it did just what it was supposed to. Substitution is generally preferable if you can get it to work because you don't have to call an external command for it.
This page has detailed tutorials for sed and awk, among other useful subjects, though truthfully I haven't gotten around to going through them myself yet. The Advanced Bash Scripting Guide I linked to earlier also has some coverage of them. |
All times are GMT -5. The time now is 02:25 PM. |