These one-liners are great for early exits (like in assertions), but I wouldn't use 'em in the normal program flow. So my ping script would look like this:
#!/bin/bash [ -z "$1" ] && echo "host required" && exit 1 ping -c 1 if [ $? -eq 0 ]; then echo "$1 reachable." fi exit 0
I think it's easier to see what part of the code belongs to error handling and what's the business logic.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
These one-liners are great for early exits (like in assertions), but I wouldn't use 'em in the normal program flow. So my ping script would look like this:
I think it's easier to see what part of the code belongs to error handling and what's the business logic.