Register
It is currently Fri Apr 25, 2014 3:18 am

Some problems with a couple of conditional statements


All times are UTC - 6 hours


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 PostPosted: Sun May 01, 2011 10:49 am   

Joined: Sun May 01, 2011 10:30 am
Posts: 4
Heya!

I'm writing a bash script that among other things has a function that will stop the script if an argument is included in a string, but will continue to run if an exclusion is available in another string. Like this:


Code:
denydirs="foo*|bar*"
exclusions="foo-bar|bar-foo"

some_function() {
    if [[ ! ${2} =~ .*(${exclusions}).* && ${2} =~ .*(${denydirs}).* ]]; then
        exit 1
    else
        other_function "$2"
    fi
}



and the function is called from another function further down the script by:
Code:
some_function "$2"




Now, this is weird, but the function above used to work just fine, but all of a sudden for some reason it has stopped working and I can't figure out what I'm doing wrong so I thought i should ask the expertise here about it :).

Here's another example of something that stopped working but was working before:

Code:
yet_another_function() {

    if [[ "${#}" != 2 ]] || [[ ${debug_mode} == 0 && "${#}" != 3 ]]; then
        ...
}


This i could easily rewrite to get it working again, but I'm stuck at the first example

So what is it that I'm doing wrong here?


Top
 Profile  
 PostPosted: Sun May 01, 2011 12:58 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 512
Hi,

what's your shebang?


Top
 Profile  
 PostPosted: Sun May 01, 2011 1:31 pm   

Joined: Sun May 01, 2011 10:30 am
Posts: 4
Watael wrote:
Hi,

what's your shebang?


It's #!/bin/bash


Top
 Profile  
 PostPosted: Sun May 01, 2011 1:46 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 512
how do you execute the script?


Top
 Profile  
 PostPosted: Sun May 01, 2011 5:46 pm   

Joined: Sun May 01, 2011 10:30 am
Posts: 4
$ ./script.sh -sh /path/to/foofoo

I've verified the contents of $2, $denydirs and $exclusions by echoing them right before the now non-functioning row, but the match is never made so the script continues no matter what i feed it.


Top
 Profile  
 PostPosted: Sun May 01, 2011 7:43 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 512
that's weird :(
it works all right here
Code:
$ ./rewt-BS nm /path/to/foofoo
+ exclusions='foo-bar|bar-foo'
+ denydirs='foo*|bar*'
+ some_function -sh /path/to/foofoo
+ [[ ! /path/to/foofoo =~ .*(foo-bar|bar-foo).* ]]
+ [[ /path/to/foofoo =~ .*(foo*|bar*).* ]]
+ exit 1
Code:
$ ./rewt-BS nm /path/to/foo-bar
+ exclusions='foo-bar|bar-foo'
+ denydirs='foo*|bar*'
+ some_function nm /path/to/foo-bar
+ [[ ! /path/to/foo-bar =~ .*(foo-bar|bar-foo).* ]]
+ echo other_function
other_function
:-/


Top
 Profile  
 PostPosted: Mon May 02, 2011 9:22 am   

Joined: Sun May 01, 2011 10:30 am
Posts: 4
I found out what the problem is.

I had an unescaped "(foo)" in exclusions, and "*foo|*bar" in denydirs. Gotta rewrite this a bit i think. Thanks for your time.


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

All times are UTC - 6 hours


Who is online

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