Scripts
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb Site ManagementScripts

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 7th, 2007, 07:41 PM
Matt1776's Avatar
Matt1776 Matt1776 is offline
Recovering Intellectual
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Orange County, CA
Posts: 1,009 Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 21 h 56 m 37 sec
Reputation Power: 442
Send a message via ICQ to Matt1776 Send a message via AIM to Matt1776 Send a message via MSN to Matt1776 Send a message via Yahoo to Matt1776 Send a message via Skype to Matt1776
Bash question

I have some lines of code that will not port from bash version 3.1 to bash 2.0 something.

I need to know how I could make this work in earlier versions of bash shell that did not have the regex bind operator:

Code:
if [[ "$IT" =~ "s" ]] && [[ ! "$INIT" =~ "$TD=" ]]
__________________
Bugs that go away by themselves come back by themselves
Never take life seriously, Nobody gets out alive anyway.

Reply With Quote
  #2  
Old September 10th, 2007, 09:09 PM
Matt1776's Avatar
Matt1776 Matt1776 is offline
Recovering Intellectual
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Orange County, CA
Posts: 1,009 Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 21 h 56 m 37 sec
Reputation Power: 442
Send a message via ICQ to Matt1776 Send a message via AIM to Matt1776 Send a message via MSN to Matt1776 Send a message via Yahoo to Matt1776 Send a message via Skype to Matt1776
Bump.

I'm seriously at a loss here. Are there any bash wizards in the audience .. perhaps any circa *before version 3.0 of Bash* wasn't that long ago ....

Need to know how *test* with regular expression? Ive tried using grep with little success, thought I might use that and then test the variable but alas.

Anyone? Thanks in advance.

Reply With Quote
  #3  
Old September 10th, 2007, 09:25 PM
bullet's Avatar
bullet bullet is offline
Java Junkie
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jan 2004
Location: Mobile, Alabama
Posts: 3,279 bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level)bullet User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 15 h 28 m 10 sec
Reputation Power: 309
Send a message via ICQ to bullet Send a message via AIM to bullet Send a message via MSN to bullet
Quote:
Originally Posted by Matt1776
Bump.

I'm seriously at a loss here. Are there any bash wizards in the audience .. perhaps any circa *before version 3.0 of Bash* wasn't that long ago ....

Need to know how *test* with regular expression? Ive tried using grep with little success, thought I might use that and then test the variable but alas.

Anyone? Thanks in advance.


Could you make use of substring extraction?

Reply With Quote
  #4  
Old September 10th, 2007, 09:32 PM
Matt1776's Avatar
Matt1776 Matt1776 is offline
Recovering Intellectual
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Orange County, CA
Posts: 1,009 Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 21 h 56 m 37 sec
Reputation Power: 442
Send a message via ICQ to Matt1776 Send a message via AIM to Matt1776 Send a message via MSN to Matt1776 Send a message via Yahoo to Matt1776 Send a message via Skype to Matt1776
Well .. lets see ..

The first test does a match on some time .. that might work because there wont ever be a 00:00s only 0:00s (this is a dicing and matching of the data received from the `w` command).

The second match .. probably not .. its a space separated list of custom data (fields from the command reorganized around a `=` with a little bit of AwK) Problem there is I dont know the order, so I wouldn't know the length or position of the current device im looking at (I broke it down by tty numbers for uniqueness).


Here is some of the script to give an idea:
Code:
while : ; do

INP=`w -h | awk '{ print $2"="$5 }'`

for IDX in $INP ; do
    TD=`echo $IDX | awk -F'=' '{ print $1 }' | sed 's/[^0-9]//g'`
    IT=`echo $IDX | awk -F'=' '{ print $2 }'`

if [[ "$IT" =~ "s" ]] && [[ ! "$INIT" =~ "$TD=" ]] ; then
    ST=`date '+%s'`
    INIT="$INIT $TD=$ST"
fi


....

Reply With Quote
  #5  
Old September 12th, 2007, 12:09 PM
Matt1776's Avatar
Matt1776 Matt1776 is offline
Recovering Intellectual
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Orange County, CA
Posts: 1,009 Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 21 h 56 m 37 sec
Reputation Power: 442
Send a message via ICQ to Matt1776 Send a message via AIM to Matt1776 Send a message via MSN to Matt1776 Send a message via Yahoo to Matt1776 Send a message via Skype to Matt1776
Here is the appropriate conversion .. this ports well:

This:

Code:
if [[ "$IT" =~ "s" ]] && [[ ! "$INIT" =~ "$TD=" ]]


Becomes this:

Code:
if [ `echo "$IT" | grep -c "s"` ] && [ ! `echo "$INIT" | grep -c "$TD="` ]



Test requires a binary expression so grep -c gives you a positive integer when the match is made, zero if it isnt.

Reply With Quote
  #6  
Old September 12th, 2007, 12:26 PM
Matt1776's Avatar
Matt1776 Matt1776 is offline
Recovering Intellectual
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Orange County, CA
Posts: 1,009 Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Matt1776 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 21 h 56 m 37 sec
Reputation Power: 442
Send a message via ICQ to Matt1776 Send a message via AIM to Matt1776 Send a message via MSN to Matt1776 Send a message via Yahoo to Matt1776 Send a message via Skype to Matt1776
And to continue this conversation with myself, the previous lines of code were not actually correct.

`test` will return true if its only argument is not-null. So when the result of the grep returned zero the test still returned true because 0 != "" .. so it must be written this way:

Code:
if [ `echo "$IT" | grep -c "s"` -gt 0 ] && [ `echo "$INIT" | grep -c "$TD="` -lt 1 ]

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb Site ManagementScripts > Bash question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT