how can I compare two characters in shell script?
similar to C++ code:
char ch='a';
if(ch=='a')
{
do_something;
}
how can I compare two characters in shell script?
similar to C++ code:
char ch='a';
if(ch=='a')
{
do_something;
}
ch="a"
if [ $ch == "a" ]; then
do_something
fi
i have something like this and i get the error: ./proiect: line 19: [: ==: unary operator expected
while read -n1 char; do
if [ $char == "a" ]
then
((i++))
fi
done < file
Use = instead of ==
if [ "$char" = a ]
this works perfect,thanks
BASH has == , which can cause some bad habits when many other shells don't.