Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7914905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:16:32+00:00 2026-06-03T14:16:32+00:00

I want to use the conditional regexp structure from bash, present since the third

  • 0

I want to use the “conditional regexp” structure from bash, present since the third version of bash (circa 2004).
It’s supposed to go like this:

if [[ $string =~ $regexp ]]; then
#do smthg
else
#do somthg else
fi

So here’s my code, following this structure, and its role is to check if the name contained in SSID is presend in the output from iw dev wlan0 link :

if [[ $(iw dev wlan0 link) =~ $SSID+ ]]; then 
    #do sthming 
else
    echo "wrong network"

fi

For some reason that i can’t decipher, this statement works pretty well if I run it right into the bash shell, like

if [[ $(iw dev wlan0 link) =~ $SSID+ ]]; then echo found; else echo not found; fi

But if i run it inside the script its contained, it’ll spit out:

scripts/ssidchecker.sh: 22: [[: not found

22 being the line of the “fi” keyword. The strangest thing is that it will always execute the code contained in the “else” statement

Is “not found” meant to indicate me that the regexp dind’t find anything in that string? Is it a real error message?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:16:35+00:00Added an answer on June 3, 2026 at 2:16 pm

    Starting Note: Answer created with input from comments in question, especially in response of the last comment.

    First, what is [[? It is a shell keyword.

    samveen@maverick:~$ type [[
    [[ is a shell keyword
    

    This means that [[ is an internal keyword of bash, not a command and thus will not work with other shells. Thus, your error output

    scripts/ssidchecker.sh: 22: [[: not found
    

    means that the shell you’re using is probably

    • Not bash
    • A version of bash older than 2.02 ([[ introduced in Bash-2.02)

    Given that 2.02 is a really really old version (pre Y2K), all this just points to the fact that the shell you’re using to run the script is probably not /bin/bash, instead probably being /bin/sh which is the most common path used for Bourne shell scripts shebang (the #!) line.

    Please change that to /bin/bash or explicitly run bash scripts/ssidchecker.sh and you’re good to go.

    As to why the else section was always executed, the [[ command not being found is the same as a failure (non-zero return value), from the viewpoint of if. Thus the else section is executed.

    samveen@maverick:~$ /bin/whosyourdaddy
    -bash: /bin/whosyourdaddy: No such file or directory
    samveen@maverick:~$ echo $?
    127
    

    As a side note on portability, the bash hackers wiki also says the following about the [[ keyword:

    Amongst the major “POSIX-shell superset languages” (for lack of a
    better term) which do have [[, the test expression compound command is
    one of the very most portable non-POSIX features. Aside from the =~
    operator
    , almost every major feature is consistent between Ksh88,
    Ksh93, mksh, Zsh, and Bash. Ksh93 also adds a large number of unique
    pattern matching features not supported by other shells including
    support for several different regex dialects, which are invoked using
    a different syntax from Bash’s =~, though =~ is still supported by ksh
    and defaults to ERE.

    Thus your script will probably fail on the =~ even if the shell supports [[, in case the shell isn’t bash but supports [[.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use conditional binding in ninject, based on passed parameters. I have
I want to use conditional css in my datatable. Here is my code. <ui:repeat
I want to create conditional comments in XSLT. But when I use this: <!--
i want use some data from a website with web service. i have a
I want to use the conditional attribute on a class, or more to the
In C#.Net, We would use Conditional Statement like this below: string Place = TextBox1.Text
Is there an analogous conditional-not-present attribute or maybe a way to use the Conditional
I have some php conditional logic...basically I want to use jQuery to show or
How to use Conditional where clause in Mysql? Select * from table where SubId='1'
I want to use conditional comments to make a DIV appear ONLY in browsers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.