![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to check if a variable contains a . | gekkos | Shell Programming and Scripting | 3 | 11-27-2008 03:00 PM |
| how to check string of character | manas_ranjan | Shell Programming and Scripting | 9 | 05-12-2008 07:20 AM |
| read string, check string length and cut | ozzy80 | Shell Programming and Scripting | 9 | 03-21-2007 05:56 PM |
| check whether variable number or string | rolex.mp | UNIX for Dummies Questions & Answers | 4 | 02-22-2007 12:12 AM |
| How to check a string in the variable | josephwong | Shell Programming and Scripting | 1 | 06-26-2006 12:14 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Quote:
All the mentioned solutions use an external tool (basename, grep, etc.), which means the script has to load a program an run that and only after its completion it can resume its work. This costs some amount of time. If you do it only rarely you will barely notice the difference, if you do it in the middle of a loop which is often executed you will notice a severe difference. Having said this, here is a solution completely done in shell only - no external tools used: Code:
# x="/a/b/c/d/e" # uncomment this and comment the next line - no difference
x="/a/b/c/d/e/"
y="f" # comment this, uncomment the following line and run again
# y="e"
x="${%%x/}" # remove trailing slash if there is one
if [ "${x##*/}" = "$y" ] ; then
echo "x and y are equal"
else
echo "x and y are different"
fi
bakunin |
|
||||
|
hi
echo "$x" | egrep "AF|GN" if [[ "$?" -eq 0 ]]; then echo NO OK fi the problem in the above is that it echos $x. Is there a better if statement that says: if [ $x contains these characters: AF or GN ] then echo NOT OK fi thanks |
![]() |
| Bookmarks |
| Tags |
| awk, awk trim, trim, trim awk |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|