Click to See Complete Forum and Search --> : Bash script / Multiple lines treated as one
paulster
12-06-2001, 03:27 PM
How would I make multiple lines get treated as one line on a bash script.
Example:
<command>
line 1
line 2
line 3
line 4
<end command>
bwkaz
12-06-2001, 03:45 PM
You may be able to just put single quotes around the set of lines. Or put a backslash at the end of each line to continue it on the next.
This may not be appropriate, though, depending on what you're trying to do. If it doesn't work, could we see some examples of what you're doing?
[ 06 December 2001: Message edited by: bwkaz ]
paulster
12-09-2001, 12:59 PM
I'm trying to create backups of what I need and am only able to use zip for I haven't been able to work out
how to do it using tar.bz2.
Below is a short version of my current file, but as you can see if i add more directories or files the lines will be incredibly long. So far in using zip I can avoid long line by adding zip to every new line but its not readable enough. Buy having one command then one file or folder per line it would be easier to understand.
#!/bin/bash
#DIRECTORIES.
zip -r /home/william/Desktop/testBackup /home/william/Desktop/Temporary /home/william/Desktop/Websites
#Files
zip /home/william/Desktop/testBackup /home/william/.ntrc/config /home/william/.ispell_english /home/william/.acrorc
Below is how I would like it for ease of understanding, but if I use the method below it won't do one line after the other.
#!/bin/bash
#DIRECTORIES.
zip -r /home/william/Desktop/testBackup
/home/william/Desktop/Temporary
/home/william/Desktop/Websites
#Files
zip /home/william/Desktop/testBackup
/home/william/.ntrc/config
/home/william/.ispell_english
/home/william/.acrorc
Unless I can place one file or folder per line I also can't use tar.bz for tar.bz is more demanding and as such I would have to place it all as one massive line.
Also would anyone know of a little script that I can use so that it pops up a message when its finished backing up.
bwkaz
12-09-2001, 01:29 PM
Put a backslash at the end of each file's line, like so:
#!/bin/bash
#DIRECTORIES.
zip -r /home/william/Desktop/testBackup \
/home/william/Desktop/Temporary \
/home/william/Desktop/Websites
#Files
zip /home/william/Desktop/testBackup \
/home/william/.ntrc/config \
/home/william/.ispell_english \
/home/william/.acrorc
If you want to "pop up" a message like in a dialog box, read up on Tcl (which is a CLI-only scripting library) and Tk (which is pretty much Tcl's GUI library). If you just want to print out a message, echo it:
echo Backup completed.
I would recommend just echoing it, because it'll be SOOOOO much simpler.
[ 09 December 2001: Message edited by: bwkaz ]
paulster
12-11-2001, 01:42 PM
Thanks bwkaz got the zip version working like a charm. Can't get tar.bz2 to do it though it keeps replacing the previous file with the next one. At the end all I end up with is the last file.
O' I forgot to mention that I can't use echo because I don't use the console I just execute the file.
Thanks to you I got zip working anyway, Unless you know what the command would be for tar.bz2.
Thanks again.
bwkaz
12-11-2001, 07:17 PM
It'd be the same for .tar.bz2:
tar cjf <backup filename here> file1 \
file2 \
file3
Or, you could emulate the append option of zip like this:
tar cjf <backup filename> file1
tar rjf <backup filename> file2
tar rjf <backup filename> file3
The -r option is part of GNU tar at least, and specifies the "append" operation.