I have a shell script which accepts a parameter. I want to check whether the parameter value contains a particular string. To the best of my knowledge, grep works on a file, not on a parameter value. How can i do a search of the string and proceed.
Not really! I've to check the paramater value against two string values. ie, i want to check the parameter value contains either "Loss" or "Profit" in it.
It will be something like this.
#! /bin/sh
$input=$1
if [ <check whether $1 contains the strings specified> ]
then
<statement 1>
else
<statement 2>
fi
All solutions satisfy your requirements, you just need to modify them as per your requirements, we can give you a start or hint, not a complete solution. Do whatever you want as per the given hints.
[/tmp]$ cat ./try.ksh
#! /bin/ksh
arg="$1"
if [[ "$arg" = @(*[lL]oss*|*[pP]rofit*) ]] ; then
echo "$arg"
else
echo "No profit or loss"
fi;
[/tmp]$ ./try.ksh "Only Profit and no Loss"
Only Profit and no Loss
[/tmp]$ ./try.ksh "We broke even"
No profit or loss
[/tmp]$
if [ "$command" = "HUAWEI_M2000_SYSTEM" ]
some times the above $command o/p is HUAWEI_M2000_SYSTEM HUAWEI_M2000_SYSTEM..so I want in if cdn to check if $command contains HUAWEI_M2000_SYSTEM it should work for then option...How to do this..
Similarly Iam getting o/p as MAINS FAIL...I need to remove the sapeces in between and convert to MAINSFAIL how to do this too..