IM trying to match "\" as a parameter when running a script. The input is "\". I have the if statement already i just need the regular expression to not return a empty string.
sorry the /* is wrong it should be \* and its "\*" a string. I will run the command and check it out (the od -c command)
---------- Post updated at 12:25 PM ---------- Previous update was at 12:04 AM ----------
So i found out the output of
echo "$domain"|od -c
is
0000000 * \n
0000002
which is right because i am trying to pass an asterisks as the first parameter when i call my script. But when the script runs , checks the parameter and get to the asterisk part of my if statement, it does not go through. Here is the part of the if statement that check for the asterisks
I know the whole if statement whole because for every other condition i get the right output. BUt when i enter a asterisks as a parameter, checkItem function does not get called. I have a feeling its the regular expression.
OK. So domain contains the single character asterisk ( * ), but your code is looking for a backslash and an asterisk ( \* ).
So, the simple way to get what you want is:
if [ "$domain" = '*' ]
then checkItem
fi
If you want to make it less efficient and use grep or egrep, that would be:
if [ "$(echo "$domain" | grep '^[*]$')" != "" ]
then checkItem
fi