Compare first characters of a string in UNIX shell
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Compare first characters of a string in UNIX shell
Hello all!
I want to verify if the first 2 characters of a string are "+-".
Can you please help me with that? How can I compare if the varaible (let's say P1 begins with "+-" )
What is it that you are looking to output from comparing the values? For example are you looking to output the number of lines in a file that starts with "+-". Knowing what type of information you are looking to gather will help me understand what type of expression you are looking for.
I need one more small thing: before this check, i want to verify first if the string variable has at least 2 characters (without doing this check i get the following error: "[: =: unary operator expected")
I need one more small thing: before this check, i want to verify first if the string variable has at least 2 characters (without doing this check i get the following error: "[: =: unary operator expected")
Thanks,
Chris
Make sure you quote the test variable, i.e. do this:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.