944,167 Members | Top Members by Rank

Ad:
Sep 8th, 2006
0

String Match Comparison

Expand Post »
Greetings Guys,

I am currently creating a frontend for a dropable application in Mac OS, for the backend I am using sh/bash.

Currently I have a for look checking to see if it a directory, however I have been unable to find a way to check and see if a string/variable contains .kext.

Mainly I want to check command line arg and throw it in an if != loop if it ($2) does not contain .kext in it.

Regards,

Mofo-X
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
toztech is offline Offline
3 posts
since Sep 2006
Sep 11th, 2006
0

Re: String Match Comparison

This checks $2 to see if ".kext" is anywhere in the $2 parameter
Shell Scripting Syntax (Toggle Plain Text)
  1. echo "$2" | grep -q '.kext'
  2. if [[ $? -eq 0 ]] ; then
  3. echo '.kext found'
  4. else
  5. echo '.kext not found'
  6. fi
Reputation Points: 62
Solved Threads: 10
Junior Poster
jim mcnamara is offline Offline
179 posts
since May 2004
Sep 11th, 2006
0

Re: String Match Comparison

Shell Scripting Syntax (Toggle Plain Text)
  1. if [[ $2 != *.kext* ]] ; then
  2. ...
  3. fi
sut
Reputation Points: 20
Solved Threads: 1
Light Poster
sut is offline Offline
30 posts
since Sep 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Making a shell script executable from any directory
Next Thread in Shell Scripting Forum Timeline: Replace text in a file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC