I am new to unix and shell scripting.In my script,there is a line using the "if" conditional -
if [$x != "," ] && [$x != ","]; then
do something
Here "x" is a variable holding string value.If it is not equal to a comma or a string,only then I want to enter the "if" loop. But I am getting error while running this. The error says - " != Expecting unary operator" . Please let me know what is wrong and how to correct it.
if [[ "$x" != "a_string" ]] && [[ "$x" != "," ]]; then
#do something
fi
While the inner closing and opening brackets I marked bold can be left away.
Also you can use the advanced search function of the forum and search thread titles with "if condition" and gets of examples, solutions and further explanations.
There is one more question. I have a string(suppose $str). If it starts with a comma(there can be more than one comma at the start),I have to remove all the commas from the beginning.So i have to check if the string starts with a comma.If it does,I have to delete all the commas which are at the start of the string.Please help.
Thanks for your reply.But what I need is,I want to delete starting commas from the variable (say $str) and the changes should be made to the original variable so that when I access $str the next time,the starting commas are not there.Please help.