Skip to content

Instantly share code, notes, and snippets.

@mpapis
Last active June 12, 2018 17:11
Show Gist options
  • Save mpapis/3044226 to your computer and use it in GitHub Desktop.
Save mpapis/3044226 to your computer and use it in GitHub Desktop.
clean if statements in shell
# dens form for short statements / commands
if [[ -n "${bla:-}" ]]
then x=bla
else x=
fi
# sparse form for long statements / more commands
if
[[ -n "${bla_asd_sf_affdfs_dsf_sdf_sdf:-}" ]] ||
[[ -n "${bar_Dfs_dsg_FG_fd_fd_df_dfgdf:-}" ]]
then
some more commands
and even more
else
or other commands
fi
# mixed for large else
if [[ -n "${bla:-}" ]]
then x=bla
else
x=...
some more commands
and even more
fi
# just else
[[ -n "${bla:-}" ]] ||
{
x=...
some more commands
and even more
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment