An “and” operator for an “if” statement in Bash

I’m trying to create a simple Bash script to check if the website is down and for some reason the “and” operator doesn’t work: #!/usr/bin/env bash WEBSITE=domain.com SUBJECT=”$WEBSITE DOWN!” EMAILID=”[email protected]” STATUS=$(curl -sI $WEBSITE | awk ‘/HTTP\/1.1/ { print $2 }’) STRING=$(curl -s $WEBSITE | grep -o “string_to_search”) VALUE=”string_to_search” if [ $STATUS -ne 200 ] && … Read more

How to avoid “if” chains?

Assuming I have this pseudo-code: bool conditionA = executeStepA(); if (conditionA){ bool conditionB = executeStepB(); if (conditionB){ bool conditionC = executeStepC(); if (conditionC){ … } } } executeThisFunctionInAnyCase(); Functions executeStepX should be executed if and only if the previous succeed. In any case, the executeThisFunctionInAnyCase function should be called at the end. I’m a newbie … Read more

JavaScript single line ‘if’ statement – best syntax, this alternative? [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 1 year ago. Improve this question It’s been clearly put, although opinion none the less, that forgoing curly brackets on a single … Read more

How to check if a string contains an element from a list in Python

I have something like this: extensionsToCheck = [‘.pdf’, ‘.doc’, ‘.xls’] for extension in extensionsToCheck: if extension in url_string: print(url_string) I am wondering what would be the more elegant way to do this in Python (without using the for loop)? I was thinking of something like this (like from C/C++), but it didn’t work: if (‘.pdf’ … Read more