echo to file - More than one paragraph

Need help with C, C++, perl, python, etc?

echo to file - More than one paragraph

Postby Gouki » 2006-08-20 01:36

Hi,

I'm trying to make a simple script, and the first thing I need to do is echo some text to a specified file.

Now echo "hello" > /home/gouki/text_file will work. But what if I need to add text with more than one paragraph, say:

Code: Select all
Hello
Hello2
Hello3


Is it possible?
Gouki
 
Posts: 53
Joined: 2006-08-19 04:26

Postby Lavene » 2006-08-20 05:30

I'm no expert in shell scripting so I cant help you directly, but when the need arises and I have to write a script I turn to this excellent guide: http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_01_05.html

Good luck :)
Tina
Lavene
Site admin
 
Posts: 5096
Joined: 2006-01-04 04:26
Location: Oslo, Norway

Postby Gouki » 2006-08-20 05:40

Hi,

I also tried that guide, but with no luck. From all the examples provided, I was not able to find something that fits my needs.

Let's see if someone knows how to do it (-:
Gouki
 
Posts: 53
Joined: 2006-08-19 04:26

Postby greenhat » 2006-08-20 11:17

put quotes around it in your script..
Code: Select all
#!/bin/bash
echo "Line1
Line2
Line3" > out.txt

or if you want to append it to the file use >> out.txt

$ cat out.txt
Line1
Line2
Line3
greenhat
 
Posts: 170
Joined: 2006-06-03 17:32

Postby Gouki » 2006-08-20 11:23

That worked like a charm! Thank you very much!
Gouki
 
Posts: 53
Joined: 2006-08-19 04:26

Postby Gouki » 2006-08-20 11:28

Another thing,

How can I add a startup script to Sessions?
Gouki
 
Posts: 53
Joined: 2006-08-19 04:26

Postby dawgie » 2006-08-20 13:38

Gouki wrote:How can I add a startup script to Sessions?


Debian uses the update-rc.d command.

First add your script to /etc/init.d directory

Then run the update-rc.d command to add your script to the startup process.

Example:
# update-rc.d myscript defaults

Or to specify a specific startup number (20 of 1-99) and the runlevel (2 3 4 5 etc) Note that there is a "dot" at the end of this line.
# update-rc.d myscript start 20 2 3 4 5 . stop 20 0 1 6 .

Kdm or Gdm are usually 99

to remove a script from the startup process:
# update-rc.d myscript remove


One thing that you don't want to do is remove or add symlinks from the runlevels by hand or you may find strange things happening when you upgrade your system.
User avatar
dawgie
 
Posts: 431
Joined: 2004-06-16 21:30
Location: New Hampshire USA

Postby Gouki » 2006-08-20 13:58

GREAT! Thank you very much.

Edit:

One last thing, I hope...

How can I add text to the bottom of a file. In this particular case, I want to add more repositories to sources.list. I was think about doing it with echo, but if there is any other way, I don't mind.
Gouki
 
Posts: 53
Joined: 2006-08-19 04:26

Postby kink » 2006-08-20 17:17

Echo is your friend, make sure you use ">>" to append the text to the end instead of ">", which just replaces:

Code: Select all
echo New line of text >> /etc/apt/sources.list
User avatar
kink
Debian Developer, Site Admin
Debian Developer, Site Admin
 
Posts: 287
Joined: 2006-01-02 16:47
Location: Utrecht, The Netherlands

Postby Gouki » 2006-08-20 21:55

Thank you very much.

I love this board! (-:
Gouki
 
Posts: 53
Joined: 2006-08-19 04:26

Postby jspilon » 2006-08-29 16:14

Gouki wrote:Another thing,

How can I add a startup script to Sessions?


What exactly do you mean by Sessions?

maybe an initscript is not the appropriate thing for what you are trying to achieve.
jspilon
 
Posts: 71
Joined: 2006-08-29 15:33
Location: Canada

Postby Chencho » 2006-09-26 09:27

Hi!
I wonder if its possible to mod the apache conf with a script.

I try to edit /etc/apache2/sites-available/default with:

echo'
<Location "/$PROY/login">
AuthType Basic
AuthName "$PROY"
AuthUserFile /var/www/.trac
Require valid-user
</Location>' >> temp

but it failds at <Location /$PROY/login> saying "No such file or directory"

I try with only one line and without " too

echo "<Location /test/login>" >> temp

But i have the same error

Someone knows how can i use /test/login as test, not as route?
Chencho
 


Return to Programming

Who is online

Users browsing this forum: No registered users and 6 guests

fashionable