Register
It is currently Mon Nov 24, 2014 3:21 am

Replace configuration text options


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Tue Jul 10, 2007 8:11 am   

Joined: Mon Apr 24, 2006 2:39 pm
Posts: 30
Location: Villahermosa
So I am using my laptop that switch between different networks, my work and my home network.

The business network is behind a firewall so I need to activate the proxy options on my browser (opera). To activate before opening the browser I can edit the configuration script.

the script will have many lines but I will have something like this.

Code:
Use HTTP=1
Use HTTPS=1
Use FTP=1


So I used vim and do a search and replace on the fly.
Code:
   vim -c "566" -c "s/1/0/"
   -c "567" -c "s/1/0/"
   -c "568" -c "s/1/0/"
   -c "wq" $file;


The problem is that this won't work. I am triying to have script_name [ On | Off]. The problem is that for some reason is not working. The command like that will work, but once I wrap it up under if I don't get an error but nothing happen.
Code:
#!/bin/bash
file="/home/user/.opera/opera6.ini"

if [ $# -eq 0 ]; then
   echo " Please insert an option,"
   echo " on - Activates Opera proxy"
   echo " off - Deactivate opera proxy"
fi

if [ $# == "Off" ]; then
   vim -c "566" -c "s/1/0/"
   -c "567" -c "s/1/0/"
   -c "568" -c "s/1/0/"
   -c "wq" $file;
fi

if [ $# == "On" ]; then
   vim -c "566" -c "s/0/1/"
   -c "567" -c "s/0/1/"
   -c "568" -c "s/0/1/"
   -c "wq" $file;
fi


Am I doing something work on the statement part within the if?


Top
 Profile WWW ICQ YIM  
 PostPosted: Tue Jul 10, 2007 4:40 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
hey jza...
first off... the $# returns a number. The number of arguments passed.
So both of your if statements will come back false. Try this:
Code:
#!/bin/bash
file="/home/user/.opera/opera6.ini"

if [ $# <> 1 ]; then
   echo " Please insert an option like:"
   echo "$0 on"
   echo " on - Activates Opera proxy"
   echo " off - Deactivate opera proxy"
   exit
fi

if [ "$1" == "Off" ]; then
   vim -c "566" -c "s/1/0/"
   -c "567" -c "s/1/0/"
   -c "568" -c "s/1/0/"
   -c "wq" $file;
fi

if [ "$1" == "On" ]; then
   vim -c "566" -c "s/0/1/"
   -c "567" -c "s/0/1/"
   -c "568" -c "s/0/1/"
   -c "wq" $file;
fi


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP