Skip to main content
Second iteration [<https://en.wiktionary.org/wiki/tread#Verb>] - as in "to step or walk (on or over something); to trample."
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 109
  • 132

Bash really confuses the issue with the likes of [, [[, ((, $((, etc.

All treatingtreading on each others' code spaces. I guess this is mostly historical, where Bash had to pretend to be sh occasionally.

Most of the time, I can just pick a method and stick with it. In this instance, I tend to declare (preferably in a common library file I can include with . in my actual script(s)).

TRUE=1; FALSE=0

I can then use the (( ... )) arithmetic operator to test thusly.

testvar=$FALSE

if [[ -d ${does_directory_exist} ]]
then
    testvar=$TRUE;
fi

if (( testvar == TRUE )); then
    # doDo stuff because the directory does exist
fi
  1. You do have to be disciplined. Your testvar must either be set to $TRUE or $FALSE at all times.

  2. In (( ... )) comparators, you don't need the preceding $, which makes it more readable.

  3. I can use (( ... )) because $TRUE=1 and $FALSE=0, i.e. numeric values.

  4. The downside is having to use a $ occasionally:

     testvar=$TRUE
    

    which is not so pretty.

It's not a perfect solution, but it covers every case, I need of such a test.

Bash really confuses the issue with the likes of [, [[, ((, $((, etc.

All treating on each others' code spaces. I guess this is mostly historical, where Bash had to pretend to be sh occasionally.

Most of the time, I can just pick a method and stick with it. In this instance, I tend to declare (preferably in a common library file I can include with . in my actual script(s)).

TRUE=1; FALSE=0

I can then use the (( ... )) arithmetic operator to test thusly.

testvar=$FALSE

if [[ -d ${does_directory_exist} ]]
then
    testvar=$TRUE;
fi

if (( testvar == TRUE )); then
    # do stuff because the directory does exist
fi
  1. You do have to be disciplined. Your testvar must either be set to $TRUE or $FALSE at all times.

  2. In (( ... )) comparators, you don't need the preceding $, which makes it more readable.

  3. I can use (( ... )) because $TRUE=1 and $FALSE=0, i.e. numeric values.

  4. The downside is having to use a $ occasionally:

     testvar=$TRUE
    

    which is not so pretty.

It's not a perfect solution, but it covers every case, I need of such a test.

Bash really confuses the issue with the likes of [, [[, ((, $((, etc.

All treading on each others' code spaces. I guess this is mostly historical, where Bash had to pretend to be sh occasionally.

Most of the time, I can just pick a method and stick with it. In this instance, I tend to declare (preferably in a common library file I can include with . in my actual script(s)).

TRUE=1; FALSE=0

I can then use the (( ... )) arithmetic operator to test thusly.

testvar=$FALSE

if [[ -d ${does_directory_exist} ]]
then
    testvar=$TRUE;
fi

if (( testvar == TRUE )); then
    # Do stuff because the directory does exist
fi
  1. You do have to be disciplined. Your testvar must either be set to $TRUE or $FALSE at all times.

  2. In (( ... )) comparators, you don't need the preceding $, which makes it more readable.

  3. I can use (( ... )) because $TRUE=1 and $FALSE=0, i.e. numeric values.

  4. The downside is having to use a $ occasionally:

     testvar=$TRUE
    

    which is not so pretty.

It's not a perfect solution, but it covers every case I need of such a test.

Active reading [<http://en.wikipedia.org/wiki/Bash_%28Unix_shell%29>].
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 109
  • 132

BASHBash really confuses the issue with the likes of [, [[, ((, $((, etcetc.

All treating on each others' code spaces. I guess this is mostly historical, where bashBash had to pretend to be sh occasionally.

Most of the time, I can just pick a method and stick with it. In this instance, I tend to declare (preferably in a common library file I can include with . in my actual script(s)).

TRUE=1; FALSE=0

I can then use the (( ... )) arithmetic operator to test thusly.

testvar=$FALSE

if [[ -d ${does_directory_exist} ]]
then
    testvar=$TRUE;
fi

if (( testvar == TRUE )); then
    # do stuff because the directory does exist
fi
  1. You do have to be disciplined, your. Your testvar must either be set to $TRUE or $FALSE at all times.

  2. In (( ... )) comparators, you don't need the preceding $, which makes it more readable.

  3. I can use (( ... )) because $TRUE=1 and $FALSE=0, i.e. numeric values.

  4. The downside is having to use a $ occasionally:

     testvar=$TRUE
    

    which is not so pretty.

which is not so pretty.

It's not a perfect solution, but it covers every case, I need of such a test.

BASH really confuses the issue with the likes of [, [[, ((, $((, etc.

All treating on each others' code spaces. I guess this is mostly historical, where bash had to pretend to be sh occasionally.

Most of the time, I can just pick a method and stick with it. In this instance, I tend to declare (preferably in a common library file I can include with . in my actual script(s)).

TRUE=1; FALSE=0

I can then use the (( ... )) arithmetic operator to test thusly.

testvar=$FALSE

if [[ -d ${does_directory_exist} ]]
then
    testvar=$TRUE;
fi

if (( testvar == TRUE )); then
    # do stuff because the directory does exist
fi
  1. You do have to be disciplined, your testvar must either be set to $TRUE or $FALSE at all times.

  2. In (( ... )) comparators, you don't need the preceding $, which makes it more readable.

  3. I can use (( ... )) because $TRUE=1 and $FALSE=0, i.e. numeric values.

  4. The downside is having to use a $ occasionally:

     testvar=$TRUE
    

which is not so pretty.

It's not a perfect solution, but it covers every case, I need of such a test.

Bash really confuses the issue with the likes of [, [[, ((, $((, etc.

All treating on each others' code spaces. I guess this is mostly historical, where Bash had to pretend to be sh occasionally.

Most of the time, I can just pick a method and stick with it. In this instance, I tend to declare (preferably in a common library file I can include with . in my actual script(s)).

TRUE=1; FALSE=0

I can then use the (( ... )) arithmetic operator to test thusly.

testvar=$FALSE

if [[ -d ${does_directory_exist} ]]
then
    testvar=$TRUE;
fi

if (( testvar == TRUE )); then
    # do stuff because the directory does exist
fi
  1. You do have to be disciplined. Your testvar must either be set to $TRUE or $FALSE at all times.

  2. In (( ... )) comparators, you don't need the preceding $, which makes it more readable.

  3. I can use (( ... )) because $TRUE=1 and $FALSE=0, i.e. numeric values.

  4. The downside is having to use a $ occasionally:

     testvar=$TRUE
    

    which is not so pretty.

It's not a perfect solution, but it covers every case, I need of such a test.

overall edited structure + formatting code = much more readable now
Source Link

BashBASH really confuses the issue with the likes of [[, [[[[, ((((, $(( etc all treading$((, etc.

All treating on each others' codespacescode spaces. I guess this is mostly historical, where bash hasbash had to pretend to be shsh occasionally.

Most timesof the time, I can just pick a method and stick with it. In this instance, I tend to declare (preferably in a common library file I can . include with . in my actual scriptsscript(s)).

TRUE=1;FALSE=0TRUE=1; FALSE=0

I can then use the (( arithmetic(( )) comparator... )) arithmetic operator to test thusly...

testvar=$FALSE
if [[ -d ${does_directory_exist} ]]; then testvar=$TRUE; fi

if (( testvar == TRUE )); then
   # do stuff 'cos directory does exist
.
.
.
fitestvar=$FALSE

if [[ -d ${does_directory_exist} ]]
then
    testvar=$TRUE;
fi

if (( testvar == TRUE )); then
    # do stuff because the directory does exist
fi
  
  1. You do have to be disciplined, your testvar must either be set to

    You do have to be disciplined, your testvar must either be set to $TRUE or $FALSE at all times.

    $TRUE or $FALSE at all times
  2. In (( )) comparators, you don't need

    In (( ... )) comparators, you don't need the preceding $, which makes it more readable.

    the preceding $, which makes it more readable
  3. I can use (( )) because $TRUE=1, $FALSE=0, i.e. numeric

    I can use (( ... )) because $TRUE=1 and $FALSE=0, i.e. numeric values.

  4. The downside is having to

    The downside is having to use a $ occasionally:

    use a $ occasionally
     testvar=$TRUE
    
testvar=$TRUE
...which is not so pretty.

which is not so pretty.

It's not a perfect solution, but it covers every case, I need of such a test... so I am satisfied with it.

Bash really confuses the issue with the likes of [, [[, ((, $(( etc all treading on each others' codespaces. I guess this is mostly historical, where bash has to pretend to be sh occasionally.

Most times, I can just pick a method and stick with it. In this instance, I tend to declare (preferably in a common library file I can . include in my actual scripts)

TRUE=1;FALSE=0

I can then use the (( arithmetic )) comparator operator to test thusly...

testvar=$FALSE
if [[ -d ${does_directory_exist} ]]; then testvar=$TRUE; fi

if (( testvar == TRUE )); then
   # do stuff 'cos directory does exist
.
.
.
fi
 
  1. You do have to be disciplined, your testvar must either be set to $TRUE or $FALSE at all times
  2. In (( )) comparators, you don't need the preceding $, which makes it more readable
  3. I can use (( )) because $TRUE=1, $FALSE=0, i.e. numeric
  4. The downside is having to use a $ occasionally
testvar=$TRUE
...which is not so pretty.

It's not a perfect solution, but it covers every case I need such a test... so I am satisfied with it.

BASH really confuses the issue with the likes of [, [[, ((, $((, etc.

All treating on each others' code spaces. I guess this is mostly historical, where bash had to pretend to be sh occasionally.

Most of the time, I can just pick a method and stick with it. In this instance, I tend to declare (preferably in a common library file I can include with . in my actual script(s)).

TRUE=1; FALSE=0

I can then use the (( ... )) arithmetic operator to test thusly.

testvar=$FALSE

if [[ -d ${does_directory_exist} ]]
then
    testvar=$TRUE;
fi

if (( testvar == TRUE )); then
    # do stuff because the directory does exist
fi
 
  1. You do have to be disciplined, your testvar must either be set to $TRUE or $FALSE at all times.

  2. In (( ... )) comparators, you don't need the preceding $, which makes it more readable.

  3. I can use (( ... )) because $TRUE=1 and $FALSE=0, i.e. numeric values.

  4. The downside is having to use a $ occasionally:

     testvar=$TRUE
    

which is not so pretty.

It's not a perfect solution, but it covers every case, I need of such a test.

Source Link
Loading