simple if's in bash scripts?
I have been looking at: http://tldp.org/LDP/Bash-Beginners-G...ect_07_01.html
but a lot of it is to do with files and numerical comparisons what would be the bash equivalent of: if (http isin $2) { do something } thanks |
I'm not sure what you want it to do exactly, but an if statement is really quite simple.
Code:
if <test>; then So if you want to know whether a variable holds a certain string, then simply use a string comparison. Code:
if [ "$var" = string ]; then However, your isin sounds more like a partial string match, which is a bit more difficult. In that case you usually need to use bash's extended [[ ]] test mechanism. This allows regex matches, among other advanced comparisons. Code:
if [[ "$var" =~ substring ]]; then All of this is explained in the Bash Beginner's Guide page you're looking at. If you want more specific help, you'll have to give us more details. |
yes "partial string match" was what I was looking for
thanks for your help - your suggestion worked |
All times are GMT -5. The time now is 06:37 AM. |