LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash script problems with "&" (https://www.linuxquestions.org/questions/programming-9/bash-script-problems-with-and-592476/)

zivs 10-17-2007 05:58 AM

Bash script problems with "&"
 
So, I try to create a simple script (first time experience at bash scripts) which blocks some banners in few sites, but i've encountered a little problem:

Code:

#!/bin/bash
echo [prefs] >> ~/.opera/urlfilter.ini
echo prioritize excludelist=1 >> ~/.opera/urlfilter.ini
echo [include] >> ~/.opera/urlfilter.ini
echo \* >> ~/.opera/urlfilter.ini
echo [exclude] >> ~/.opera/urlfilter.ini
echo &adspace= >> ~/.opera/urlfilter.ini
echo "#| NetGames Reklamas" >> ~/.opera/urlfilter.ini
echo "*://www.apollo.lv/portal/*" >> ~/.opera/urlfilter.ini
echo "Restart your Opera browser!"

The problem is that urlfilter.ini is getting splitted in every way I try to put in quotation marks &adspace= or set in front of it "\", i get two files - first one ends with [exclude] and the other one begins with #| NetGames Reklamas.

Can anyone please tell me where and what is wrong with the scriptie? Also would be very nice of you If someone could give some useful links to bash script manuals... :)

Thanks in advance!

edit
Ah, found out that I actually don't need that &adspace= line... Was just trying to reproduce the idea from one other similiar file and I guess that this line was mean't as a blockable thingie..

Anyway, just for the future knowledge - If I someday need to add such line to script, how should it look like?

jschiwal 10-17-2007 06:16 AM

The www.tldp.org (The Linux Documentation Project) has an excellent document (Advanced Bash Scripting Guide). (abs-Guide.pdf)

This book consists almost entirely of examples, with explanations in the comments.

For your type of program, HERE documents are normally used:
Code:

#!/bin/bash
cat >>~/.opera/urlfilter.ini <<EOF
[prefs]
prioritize excludelist=1
[include] >> ~/.opera/urlfilter.ini
*
[exclude]
~/.opera/urlfilter.ini
#| NetGames Reklamas
*://www.apollo.lv/portal/*
EOF

Here documents were once often in bash installation scripts.

Also look at the info bash manual. You may find it easier to read it from the konqueror browser. Try
info:bashref
in the address bar. You may need to install a "bash-doc" package to do this.

zivs 10-17-2007 06:45 AM

Thanx for your help :)

student04 10-17-2007 01:08 PM

I like giving links to helpful sites. jschiwal already gave you the tlpd site so here are two others:

http://www.panix.com/~elflord/unix/bash-tute.html

and

http://www.telematica.polito.it/mell...in20pages.html

Also, you'll find a ton of great tutorials by Googling "bash tutorials" or "bash scripting".

-AM


All times are GMT -5. The time now is 02:49 AM.