Register
It is currently Thu Nov 27, 2014 12:33 am

Using arguments


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Wed May 09, 2007 1:36 pm   

Joined: Mon Apr 24, 2006 2:39 pm
Posts: 30
Location: Villahermosa
So I got this configuration file and I want to use bash to change the value of one of the parameters. Since I didn't want to use that many regex (or any) and I am confortable wtih vim. I did that script that will modify my parametrs.

The code is the following:
Code:
#!/bin/bash

if [ $# -eq 1 ] then;

        vi -c "610" -c "s/1/0/"
           -c "611" -c "s/1/0"
           -c "612" -c "s/1/0"
           -c "wq" ~/.opera/opera6.ini
elif
        vi -c "610" -c "s/0/1"
           -c "611" -c "s/0/1"
           -c "612" -c "s/0/1"
           -c "wq" ~/.opera/opera6.ini
fi


Obviously this code doesn't work. First thing is that I want to know wha should I put as a flag definition. I put an if conditional but I think I should have used a switch/case instead.

Also this script doesnt really work, I just get something like this:
Code:
/usr/local/bin/unprox: line 9: syntax error near unexpected token `elif'
/usr/local/bin/unprox: line 9: `elif'

[/code]


Top
 Profile WWW ICQ YIM  
 PostPosted: Wed May 09, 2007 1:44 pm   

Joined: Mon Apr 24, 2006 2:39 pm
Posts: 30
Location: Villahermosa
UPDATE: I figure out the semicolon was wrongly typed.

The first condition works but the else outputs the following error:
Code:
/usr/local/bin/unprox: line 3: [: ==: unary operator expected


Top
 Profile WWW ICQ YIM  
 PostPosted: Wed May 09, 2007 4:22 pm   

Joined: Mon Apr 24, 2006 2:39 pm
Posts: 30
Location: Villahermosa
Finally solved everything I just need to add the #1 under quote:

Code:
if [ '$#' = '-eq' ] then;


In the end the final script came like this:
Code:
#!/bin/bash

if [ "$1" = "-e" ]; then
   vi -c "610" -c "s/1/0/"
                     -c "611" -c "s/1/0/"
                     -c "612" -c "s/1/0/"
                    -c "wq" ~/.opera/opera6.ini;
   else
   vi -c "610" -c "s/0/1/"
                     -c "611" -c "s/0/1/"
                    -c "612" -c "s/0/1/"
                  -c "wq" ~/.opera/opera6.ini;
   fi


Top
 Profile WWW ICQ YIM  
 PostPosted: Thu May 10, 2007 3:54 pm   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Neat! I didn't know you could script vi...

I like to use sed to edit config files (you did say you didn't want to use regex though :). The "-i" edits the file in-place:

Code:
sed -i s/'SetAutoCrashInterval=".*"'/'SetAutoCrashInterval="30"'/g windows.conf


/me hugs sed


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 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