![]() |
Bash script to check if string1 contains string2
Help! :confused:
I'm going to make a bash script that checks if string1 contains string2. So far i've got: Code:
#!/bin/bashPlease help :scratch: |
Some notes about your script:
1) you don't really need the assignment Code:
input=$(echo $@)2) you forgot to put a $ sign before the variable name inside the expression: Code:
if [ $input == .txt ]3) if using bash version 3 you can try the operator for Regular Expression Match so that your script will look like Code:
#!/bin/bash |
you can use case/esac
Code:
string1="abcdef" |
awk implementation of the same.
BEGIN { string1="abcdef" string2="abcd" if(match(string1,string2)) { print "found" } else { print "not found" } } |
you should put your code in code tags.
Or this as well: Code:
BEGIN { |
oh, ok I will do that in future . thanks for the info ghostdog :-)
|
| All times are GMT -5. The time now is 02:18 AM. |