I am trying to check if the string is in format in shell script. below is the code i am trying and the output i want to get.
Format: <datatype>(length,length) | <datatype>(length,length)
I have multiple cases with this scenario, if both datatypes have () then it should show pass, else fail.
Eg. decimal(1,0)|number(11,0) this should pass but int|number(11,0) or decimal(1,0)|int should fail.
Code1:
INPUT='decimal(1,0)|number(11,0)'
sub="[A-Z][a-z]['!@#$ %^&*()_+'][0-9][|][A-Z][a-z]['!@#$ %^&*()_+'][0-9][|]"
if [ "$INPUT" == "$sub" ]; then
echo "Passed"
else
echo "No"
fi
Code 2:
INPUT='decimal(1,0)|number(11,0)'
sub="decimal"
if [ "$INPUT" == *"("*") |"*"("*") " ]; then
echo "Passed"
else
echo "No"
fi
Any help will be fine. Also note, I am very new to shell scripting.
=~, not==, for a regular expression operation.=is a glob. And if you do want a glob, you can't quote the right-hand side -- it should be[[ $INPUT = $sub ]]-- note[[instead of[;[only supports exact comparisons (and only in[[are unquoted expansions safe)./bin/shdoesn't support[[at all, nor does it have any kind of built-in regex support, though you can evaluate globs there usingcase.caseinside ofif. Baseline POSIX-standard/bin/shsimply doesn't support any substring operation withoutcase; you need an extended shell (ksh, bash, zsh, etc) for that to be built-in.[isn't guaranteed to support==at all. The only standard-defined string comparison operator is=.