Skip to main content
Active reading.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 109
  • 132

Here is an improvement on miku's original answer, that addresses Dennis Williamson's concerns about the case, where the variable is not set:

the_world_is_flat=true

if ${the_world_is_flat:-false} ; then
    echo "Be careful not to fall off!"
fi

And to test if the variable is false:

if ! ${the_world_is_flat:-false} ; then
    echo "Be careful not to fall off!"
fi

About other cases with a nasty content in the variable, this is a problem with any external input fed to a program.

Any external input must be validated before trusting it. But that validation has to be done just once, when that input is received.

It doesn't have to impact the performance of the program by doing it on every use of the variable like Dennis Williamson suggests.

Here is an improvement on miku's original answer, that addresses Dennis Williamson's concerns about the case, where the variable is not set:

the_world_is_flat=true

if ${the_world_is_flat:-false} ; then
    echo "Be careful not to fall off!"
fi

And to test if the variable is false:

if ! ${the_world_is_flat:-false} ; then
    echo "Be careful not to fall off!"
fi

About other cases with a nasty content in the variable, this is a problem with any external input fed to a program.

Any external input must be validated before trusting it. But that validation has to be done just once, when that input is received.

It doesn't have to impact the performance of the program by doing it on every use of the variable like Dennis Williamson suggests.

Here is an improvement on miku's original answer that addresses Dennis Williamson's concerns about the case where the variable is not set:

the_world_is_flat=true

if ${the_world_is_flat:-false} ; then
    echo "Be careful not to fall off!"
fi

And to test if the variable is false:

if ! ${the_world_is_flat:-false} ; then
    echo "Be careful not to fall off!"
fi

About other cases with a nasty content in the variable, this is a problem with any external input fed to a program.

Any external input must be validated before trusting it. But that validation has to be done just once, when that input is received.

It doesn't have to impact the performance of the program by doing it on every use of the variable like Dennis Williamson suggests.

spelling + structure = overall better for readers now
Source Link
Turn
  • 6.9k
  • 33
  • 41

Here is an improvement on miku's mikuoriginal answer's original answer, that addresses Dennis Williamson's concerns about the case, where the variable is not set:

the_world_is_flat=true

if ${the_world_is_flat:-false} ; then
    echo "Be careful not to fall off!"
fi

And to test if the variable is false:

if ! ${the_world_is_flat:-false} ; then
    echo "Be careful not to fall off!"
fi

About other cases with a nasty content in the variable, this is a problem with any external input fed to a program.

Any external input must be validated before trusting it. But that validation has to be done just once, when that input is received.

It doesn't have to impact the performance of the program by doing it on every use of the variable like Dennis Williamson suggests.

Here is an improvement on miku's original answer, that addresses Dennis Williamson's concerns about the case, where the variable is not set:

the_world_is_flat=true

if ${the_world_is_flat:-false} ; then
    echo "Be careful not to fall off!"
fi

And to test if the variable is false:

if ! ${the_world_is_flat:-false} ; then
    echo "Be careful not to fall off!"
fi

About other cases with a nasty content in the variable, this is a problem with any external input fed to a program.

Any external input must be validated before trusting it. But that validation has to be done just once, when that input is received.

It doesn't have to impact the performance of the program by doing it on every use of the variable like Dennis Williamson suggests.

Here is an improvement on miku's original answer, that addresses Dennis Williamson's concerns about the case, where the variable is not set:

the_world_is_flat=true

if ${the_world_is_flat:-false} ; then
    echo "Be careful not to fall off!"
fi

And to test if the variable is false:

if ! ${the_world_is_flat:-false} ; then
    echo "Be careful not to fall off!"
fi

About other cases with a nasty content in the variable, this is a problem with any external input fed to a program.

Any external input must be validated before trusting it. But that validation has to be done just once, when that input is received.

It doesn't have to impact the performance of the program by doing it on every use of the variable like Dennis Williamson suggests.

Here is aan improvement on @miku'smiku's original answer, that addresses @dennisDennis Williamson's concerns about the case, where the variable is not set:

the_world_is_flat=true
# ...do something interesting...
if ${the_world_is_flat:-false} ; then
    echo 'Be"Be careful not to fall off!'"
fi

ToAnd to test if the variable is falsefalse:

if ! ${the_world_is_flat:-false} ; then
    echo 'Be"Be careful not to fall off!'"
fi

About the other cases (nastywith a nasty content in the variable), this is a problem with any external input fed to a program. 

Any external input must be validated before trusting it. But that validation has to be done just onceonce, when that input is received. 

It doesn't have to impact the performance of the program by doing it on every use of the variable like @dennisDennis Williamson suggests.

Here is a improvement on @miku's original answer that addresses @dennis concerns about the case where the variable is not set:

the_world_is_flat=true
# ...do something interesting...
if ${the_world_is_flat:-false} ; then
    echo 'Be careful not to fall off!'
fi

To test if the variable is false:

if ! ${the_world_is_flat:-false} ; then
    echo 'Be careful not to fall off!'
fi

About the other cases (nasty content in the variable), this is a problem with any external input fed to a program. Any external input must be validated before trusting it. But that validation has to be done just once when that input is received. It doesn't have to impact the performance of the program by doing it on every use of the variable like @dennis suggests.

Here is an improvement on miku's original answer, that addresses Dennis Williamson's concerns about the case, where the variable is not set:

the_world_is_flat=true

if ${the_world_is_flat:-false} ; then
    echo "Be careful not to fall off!"
fi

And to test if the variable is false:

if ! ${the_world_is_flat:-false} ; then
    echo "Be careful not to fall off!"
fi

About other cases with a nasty content in the variable, this is a problem with any external input fed to a program. 

Any external input must be validated before trusting it. But that validation has to be done just once, when that input is received. 

It doesn't have to impact the performance of the program by doing it on every use of the variable like Dennis Williamson suggests.

Add example of testing of false condition
Source Link
dolmen
  • 8.5k
  • 5
  • 42
  • 44
Loading
Source Link
dolmen
  • 8.5k
  • 5
  • 42
  • 44
Loading