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 8178777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:50:49+00:00 2026-06-06T23:50:49+00:00

if I have if [ ! -e $dir ]; then mkdir $dir fi work,

  • 0

if I have

if [ ! -e $dir ];
then
 mkdir $dir
fi 

work, but not

[[ ! -e $dir ]] || mkdir $dir 

why ?

Edit 0

with [[ ... I get

 line 34: [[ !: command not found

Edit 1

bash --version
GNU bash, version 3.2.25(1)-release (i686-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

Edit 2

in some case work and some case don’t work, two consecutives commands

[user@host ~]$ [ -e /tmp ] && date
-bash: [: missing `]'
[user@host ~]$ [ -e /tmp ] && date
mar jun 26 10:05:50 CLT 2012
  • 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-06T23:50:50+00:00Added an answer on June 6, 2026 at 11:50 pm

    Especially after edit 2, this really looks to me like a problem with “funny” characters, either nonprinting characters getting mixed in, or normal-looking-but-weird characters like nonbreaking spaces. These can be fairly hard to detect; things can look completely normal in an editor, and even if you view a script with something like cat -v it won’t always show funny characters clearly. If you have xxd on your system, it’s a really good way to see precisely what’s in the file. Here’s a quick demo of this type of problem:

    $ cat -v nbsptest 
    #!/bin/bash -x
    [ -e /tmp ] && date
    [ -e /tmp ] && date
    [ -e /tmp ] && date
    $ ./nbsptest 
    + '[ -e' /tmp ']'
    ./nbsptest: line 2: [ -e: command not found
    + '[' -e '/tmp ]'
    ./nbsptest: line 3: [: missing `]'
    + '[' -e /tmp ']'
    + date
    Sat Jun 30 10:53:56 PDT 2012
    $ xxd nbsptest 
    0000000: 2321 2f62 696e 2f62 6173 6820 2d78 0a5b  #!/bin/bash -x.[
    0000010: c2a0 2d65 202f 746d 7020 5d20 2626 2064  ..-e /tmp ] && d
    0000020: 6174 650a 5b20 2d65 202f 746d 70c2 a05d  ate.[ -e /tmp..]
    0000030: 2026 2620 6461 7465 0a5b 202d 6520 2f74   && date.[ -e /t
    0000040: 6d70 205d 2026 2620 6461 7465 0a         mp ] && date.
    

    The script looks completely normal with cat -v (and more, vi, etc), but the first two commands fail. xxd shows why: the first command has a UTF-8 nonbreaking space between the [ and the -e (this shows as c2a0 in the hex listing, [..-e in the text listing) and the second command has a nonbreaking space between /tmp and ] (/tmp..] in the text listing).

    The -x display (I used bash -x to invoke it, you can also use set -x as @CodeGnome suggested) also gives a hint about what’s going on. For the first command, it listed it as '[ -e' /tmp ']' — note the quotes around [ -e, which indicates that the shell is treating that all as one “word”, which means it doesn’t think that’s a space in the middle of it. Similarly, the second command is displayed as '[' -e '/tmp ]' with the quotes indicating that it thinks /tmp ] is all one “word”.

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

Sidebar

Related Questions

I have scrip contain command line: set dir=%1 cd %dir% test.bat echo successful When
I have next command in my batch script dir project\*.java /s /B > temp_file
I have the following bash script: #DIR is something like: /home/foo/foobar/test/ without any whitespace
<target name=init> <mkdir dir=${build.dir} /> <if> <available file=../war type=dir/> <then></then> <else> <mkdir dir=../war />
I have a share backup bash script that works as is, but it uses
I have a directory Dir in which I have about 30 sub-directories. From these
If I have example.com/dir and dir is basically a folder in the example.com server,
when I write Python code from the interpreter I can type dir() to have
I have a directory /tmp/dir with two types of file names /tmp/dir/abc-something-server.log /tmp/dir/xyz-something-server.log ..
Say I have this url: http://site.example/dir/ In this folder I have these files: test.ascx.cs

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.