Understanding the Bash if statement that invokes a command

Does anyone know what this does:

if ! /fgallery/fgallery -v -j3 /images /usr/share/nginx/html/ "${GALLERY_TITLE:-Gallery}"; then
  mkdir -p /usr/share/nginx/html

      

I understand that the first part says that if the directory /fgallery/fgallery

doesn't exist, but after that it is not clear to me.

+3


source to share


1 answer


In Bash, we can plot if

based on the exit state of a command like this:

if command; then
  echo "Command succeeded"
else
  echo "Command failed"
fi

      

then

part is executed when the command exits from 0 and else

otherwise.

Your code does exactly that.

It can be rewritten as:



/fgallery/fgallery -v -j3 /images /usr/share/nginx/html/ "${GALLERY_TITLE:-Gallery}"; fgallery_status=$?
if [ "$fgallery_status" -ne 0 ]; then
  mkdir -p /usr/share/nginx/html
fi

      

But the old design is more elegant and less error prone.


See these posts:

+3


source







All Articles