From wolfrising at gmail.com Mon Aug 8 08:33:13 2005 From: wolfrising at gmail.com (Wolf Rising) Date: Mon Aug 8 08:33:18 2005 Subject: [prog] php and formatting html tables Message-ID: <72372a0905080715333fefe4fc@mail.gmail.com> Hi, I have this bit of code which prints out one large table: echo ''; while($row = mysql_fetch_assoc($result)){ //display info to page echo ''; echo ''; echo ''; echo ''; }//end while loop echo '
' . $row['BlgNo'] . ''; echo '' . $row['name'] . '' . $row['date'] . '
'; and this is the result +--------+--------+---------------+ | BlgNo | name | date | +--------+--------+---------------+ | 1 | Bob | 2005-07-23 | | 1 | Ralph | 2005-07-17 | | 1 | Jean | 2005-07-18 | | 1 | Mich | 2005-07-22 | | 1 | Jacki | 2005-07-15 | | 1 | Anne | 2005-07-19 | | 2 | Tom | 2005-07-15 | | 2 | B.J. | 2005-07-31 | | 2 | Ann | 2005-07-07 | | 2 | Sandy | 2005-07-06 | | 2 | Kyle | 2005-07-01 | | 3 | Chris | 2005-07-15 | | 3 | Jerry | 2005-07-18 | | 3 | Steve | 2005-07-15 | | 3 | Susan | 2005-07-25 | +--------+--------+---------------+ what I would like to have is for it to break into separate tables per building number (this is a small print out there are 10 buildings): +--------+--------+---------------+ | BlgNo | name | date | +--------+--------+---------------+ | 1 | Bob | 2005-07-23 | | 1 | Ralph | 2005-07-17 | | 1 | Jean | 2005-07-18 | | 1 | Mich | 2005-07-22 | | 1 | Jacki | 2005-07-15 | | 1 | Anne | 2005-07-19 | +--------+--------+---------------+ +--------+--------+---------------+ | BlgNo | name | date | +--------+--------+---------------+ | 2 | Tom | 2005-07-15 | | 2 | B.J. | 2005-07-31 | | 2 | Ann | 2005-07-07 | | 2 | Sandy | 2005-07-06 | | 2 | Kyle | 2005-07-01 | +--------+--------+---------------+ +--------+--------+---------------+ | BlgNo | name | date | +--------+--------+---------------+ | 3 | Chris | 2005-07-15 | | 3 | Jerry | 2005-07-18 | | 3 | Steve | 2005-07-15 | | 3 | Susan | 2005-07-25 | +--------+--------+---------------+ is it possible to modify the loop so it would print separate tables? I tried adding an if statement if($row['Blg'] ==1) but that didn't work out very well and it would get kinda messy. Thanks! From mary-linuxchix at puzzling.org Mon Aug 8 08:50:37 2005 From: mary-linuxchix at puzzling.org (Mary) Date: Mon Aug 8 08:51:19 2005 Subject: [prog] php and formatting html tables In-Reply-To: <72372a0905080715333fefe4fc@mail.gmail.com> References: <72372a0905080715333fefe4fc@mail.gmail.com> Message-ID: <20050807225037.GC20979@sourdust.home.puzzling.org> On Sun, Aug 07, 2005, Wolf Rising wrote: > is it possible to modify the loop so it would print separate tables? I > tried adding an if statement if($row['Blg'] ==1) but that didn't work > out very well and it would get kinda messy. It would also not be very flexible... what happens when $row['Blg'] == 4 or $row['Blg'] == 1000000. In programming you should try and solve the general problem... My PHP isn't so good, so here's the solution I'd use in a kind of pseudo-code mixed with PHP, comments begin with # # store the current Blg value currentBlg = Nothing print '' while $row == mysql_fetch_row { # capture the very first $row['Blg'] value, so that we can end # the first table when the time comes. if $currentBlg is equal to Nothing { $currentBlg = currentBlg = $row['Blg'] } # if this $row['Blg'] value is not the same as the last row, then # it's time for a new table if $row['Blg'] does not equal currentBlg { # end the current table and start a new one print '
' print '' # store the new currentBlg so that we can end this table # at the right time currentBlg = $row['Blg'] } print the $row value } # end the final table print '
' This makes several assumptions: the biggest is that the results are sorted by their Blg value. If they aren't, for example if they come out as 1, 2, 1, 1, 2, 3, 2, 1, then you will get a table every time it changes value. This particular idiom of storing the current value of something and then taking a particular action when it changes is a very common technique. A similar one is used to find the maximum value of a list, for example: 1. set the current maximum to the first value in the list 2. for each item in the list, if the item is bigger than the current maximum, make it the new current maximum 3. the current maximum is now set to the biggest item in the list -Mary From breakthru at inwind.it Mon Aug 8 08:57:41 2005 From: breakthru at inwind.it (Marco Linux) Date: Mon Aug 8 08:55:55 2005 Subject: [prog] php and formatting html tables In-Reply-To: <72372a0905080715333fefe4fc@mail.gmail.com> References: <72372a0905080715333fefe4fc@mail.gmail.com> Message-ID: <200508080057.41679.breakthru@inwind.it> Alle 00:33, luned? 8 agosto 2005, Wolf Rising ha scritto: > Hi, > > I have this bit of code which prints out one large table: > > echo ''; > while($row = mysql_fetch_assoc($result)){ > //display info to page > echo ''; > echo ''; > echo ''; > echo ''; > }//end while loop > echo '
' . $row['BlgNo'] . ''; > echo '' . $row['name'] . '' . $row['date'] . '
'; > > what I would like to have is for it to break into separate tables per > building number (this is a small print out there are 10 buildings): you could use an auxiliary variable.. // inizialize to the first entry. $CurrentB = 1; //this may be a problem,getting the first entry. ?echo ''; ? ? ?while($row = mysql_fetch_assoc($result)){ // if the BigNo value has changed, close table and open the next one if ($row['BigNo']!=$CurrentB) echo '\n
Header\n'; ? ? //display info to page ? ? ?echo ''; ? ? ?echo ''; ? ? ?echo ''; ? ? ?echo ''; // update the curent BigNo. $CurrentB = $row['BigNo']; }//end while loop ? ? ? ?echo '
' . $row['BlgNo'] . ''; ? ? ?echo '' . $row['name'] . '' . $row['date'] ?. '
'; This is the first time i post here. I hope that helps. My name is Marco, i am from Naples, Italy. From acknak_halflife at yahoo.co.uk Fri Aug 12 17:23:14 2005 From: acknak_halflife at yahoo.co.uk (Noir) Date: Fri Aug 12 17:30:01 2005 Subject: [prog] user bash script Message-ID: <20050812072314.38129.qmail@web26004.mail.ukl.yahoo.com> I am writing a bash script to adduser which will first check if the u_name exist in /etc/passwd file. My code: uname="`echo $uname | tr "[A-Z]" "[a-z]"`" avail="`cat /etc/passwd | grep ^$uname:`" if [ -e "$avail" ]; then echo "The name already exist Please try again"; exit 1; fi It gives an errror that username already exist but then goes on to add the user. ___________________________________________________________ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com From johnc+linuxchix at kirriwa.net Fri Aug 12 18:53:36 2005 From: johnc+linuxchix at kirriwa.net (John Clarke) Date: Fri Aug 12 18:59:38 2005 Subject: [prog] user bash script In-Reply-To: <20050812072314.38129.qmail@web26004.mail.ukl.yahoo.com>; from acknak_halflife@yahoo.co.uk on Fri, Aug 12, 2005 at 08:23:14 +0100 References: <20050812072314.38129.qmail@web26004.mail.ukl.yahoo.com> Message-ID: <20050812185336.A21195@kirriwa.net> On Fri, Aug 12, 2005 at 08:23:14 +0100, Noir wrote: > I am writing a bash script to adduser which will first > check if the u_name exist in /etc/passwd file. My > code: > > uname="`echo $uname | tr "[A-Z]" "[a-z]"`" There's nothing wrong with this, but I'd suggest using grep's case-insensitive matching instead to save this step. > avail="`cat /etc/passwd | grep ^$uname:`" Rather than cat the file and pipe it to grep, give grep the filename and have it read it directly. Do both of these and you reduce three shell commands (tr, cat, grep) and two pipes to a single shell command (grep). I'm not counting `echo' because it's a bash built-in. > if [ -e "$avail" ]; then This won't work because `-e' tests that a file exists, not that the string is not empty. `-n' is what you should be using. Here's how I'd do it: if test -n "`grep -i ^$uname: /etc/passwd`" then echo "User $uname already exists" exit 1 fi but only if I was the only one who could use it. Otherwise I'd make sure to sanitise $uname first to strip out shell meta-characters and anything else that shouldn't appear in a username. Cheers, John -- With a Dremel tool and a cut-off wheel, _everything_ takes a flat-blade screwdriver. -- Matt Roberds From dominik.schramm at slivery.cotse.net Fri Aug 12 19:36:06 2005 From: dominik.schramm at slivery.cotse.net (Dominik Schramm) Date: Fri Aug 12 19:44:30 2005 Subject: [prog] user bash script In-Reply-To: <20050812185336.A21195@kirriwa.net> (John Clarke's message of "Fri, 12 Aug 2005 18:53:36 +1000") References: <20050812072314.38129.qmail@web26004.mail.ukl.yahoo.com> <20050812185336.A21195@kirriwa.net> Message-ID: <200508120936.j7C9a3bT001422@www.cotse.net> Hi, John Clarke writes: > if test -n "`grep -i ^$uname: /etc/passwd`" > then > echo "User $uname already exists" > exit 1 > fi and you could further shorten even this: if grep -q -i "^$uname:" /etc/passwd then ... fi or: if grep -qi "^$uname:" /etc/passwd then ... fi grep returns 0 in case of matches, 1 otherwise. "-q" means suppress output (i.e.: of matches). That leaves the return code, which is enough to decide whether the user exists or not. dominik From mail at vosat.de Fri Aug 12 19:19:14 2005 From: mail at vosat.de (Danijel Tasov) Date: Fri Aug 12 19:52:15 2005 Subject: [prog] user bash script In-Reply-To: <20050812072314.38129.qmail@web26004.mail.ukl.yahoo.com> References: <20050812072314.38129.qmail@web26004.mail.ukl.yahoo.com> Message-ID: <20050812091914.GB2910@knast.titta5.server-king.de> Noir wrote: > I am writing a bash script to adduser which will first > check if the u_name exist in /etc/passwd file. My > code: > > uname="`echo $uname | tr "[A-Z]" "[a-z]"`" And then simply do: if id "$user" ; then echo "user already exists" >&2 exit 1 fi -DaTa Danijel Tasov -- In any event, the real geeks will probably just have the screen tattooed on their chest. Or their stomachs. Teletubbies "R" us. -- Larry Wall, 8th State of the Onion From acknak_halflife at yahoo.co.uk Fri Aug 12 21:32:25 2005 From: acknak_halflife at yahoo.co.uk (Noir) Date: Fri Aug 12 21:32:32 2005 Subject: [prog] [Solved] user bash script In-Reply-To: <20050812185336.A21195@kirriwa.net> Message-ID: <20050812113225.91097.qmail@web26003.mail.ukl.yahoo.com> > echo "User $uname already exists" > exit 1 > fi Thanks to John, Kaitlyn, Danijel and Dominik. I solved the problem. ___________________________________________________________ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com From nicki at virtualnicki.com Fri Aug 19 04:53:51 2005 From: nicki at virtualnicki.com (Nicki Handy) Date: Fri Aug 19 05:06:11 2005 Subject: [prog] setting referer checking on in php Message-ID: <28e69f4971c033cfdeb4c0c9c4ba6bd7@virtualnicki.com> Hi- I've just upgraded a mac to Tiger and also upgraded the mail server. I copied the old php.ini over into the new settings but for some reason formmail.php is not working. I didn't set it up, one of the programmers I work with uses it. The error I get in the web logs says [PHPFormMail] HTTP_REFERER checking is turned off. So, I think this would make it fail and thus, no mail from the form. But I went into php.ini and the variable for referer is set to blank. I tried changing it to 1 and "on" but neither worked. Is there another way to set that? Or is that a misleading error and I do in fact have it turned on? I restarted the server after changing it. Thanks a lot, Nicki From april at farstrider.org Fri Aug 19 06:32:46 2005 From: april at farstrider.org (April) Date: Fri Aug 19 06:37:33 2005 Subject: [prog] setting referer checking on in php In-Reply-To: <28e69f4971c033cfdeb4c0c9c4ba6bd7@virtualnicki.com> References: <28e69f4971c033cfdeb4c0c9c4ba6bd7@virtualnicki.com> Message-ID: <4304F06E.4040707@farstrider.org> I think it's a misleading error. HTTP_REFERER can be spoofed or left unset by a browser, so it's unlikely that not having that data would make the script fail silently. Would you be willing to send the formmail.php file? It could be failing for any number of reasons, but my guess is it's because register_globals went from on to off (likely if you upgraded PHP from pre-4.2). If it DID stop working because of register_globals getting turned on, that probably means the script is insecure and could be used by third parties to send spam from your server. So don't just turn on register_globals to make it work.. fix the script. Nicki Handy wrote: > Hi- I've just upgraded a mac to Tiger and also upgraded the mail server. > I copied the old php.ini over into the new settings but for some reason > formmail.php is not working. I didn't set it up, one of the programmers > I work with uses it. The error I get in the web logs says > [PHPFormMail] HTTP_REFERER checking is turned off. > > So, I think this would make it fail and thus, no mail from the form. But > I went into php.ini and the variable for referer is set to blank. I > tried changing it to 1 and "on" but neither worked. Is there another way > to set that? Or is that a misleading error and I do in fact have it > turned on? I restarted the server after changing it. > > Thanks a lot, > Nicki > > > _______________________________________________ > Programming mailing list > Programming@linuxchix.org > http://mailman.linuxchix.org/mailman/listinfo/programming > > > From nicki at virtualnicki.com Fri Aug 19 22:45:43 2005 From: nicki at virtualnicki.com (Nicki Handy) Date: Fri Aug 19 22:45:36 2005 Subject: [prog] setting referer checking on in php In-Reply-To: <20050819020012.E258D2731D0@www.linuxchix.org> References: <20050819020012.E258D2731D0@www.linuxchix.org> Message-ID: <8e4698293997f56db41b80a92ce7ff0a@virtualnicki.com> I actually don' think mail is working on the machine. I can send mail through an interface but I can't send it from the command line using mail skdjf@ksdh.com etc. I'm on mac osx. The GUI interface I set up for an exchange mail account. But from the command line I don't set any of those things so maybe that's my problem? Nicki On Aug 18, 2005, at 10:00 PM, programming-request@linuxchix.org wrote: > Send Programming mailing list submissions to > programming@linuxchix.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mailman.linuxchix.org/mailman/listinfo/programming > or, via email, send a message with subject or body 'help' to > programming-request@linuxchix.org > > You can reach the person managing the list at > programming-owner@linuxchix.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Programming digest..." > > > Today's Topics: > > 1. setting referer checking on in php (Nicki Handy) > 2. Re: setting referer checking on in php (April) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Thu, 18 Aug 2005 14:53:51 -0400 > From: Nicki Handy > Subject: [prog] setting referer checking on in php > To: programming@linuxchix.org > Message-ID: <28e69f4971c033cfdeb4c0c9c4ba6bd7@virtualnicki.com> > Content-Type: text/plain; charset=US-ASCII; format=flowed > > Hi- I've just upgraded a mac to Tiger and also upgraded the mail > server. I copied the old php.ini over into the new settings but for > some reason formmail.php is not working. I didn't set it up, one of the > programmers I work with uses it. The error I get in the web logs says > [PHPFormMail] HTTP_REFERER checking is turned off. > > So, I think this would make it fail and thus, no mail from the form. > But I went into php.ini and the variable for referer is set to blank. I > tried changing it to 1 and "on" but neither worked. Is there another > way to set that? Or is that a misleading error and I do in fact have it > turned on? I restarted the server after changing it. > > Thanks a lot, > Nicki > > > > > ------------------------------ > > Message: 2 > Date: Thu, 18 Aug 2005 13:32:46 -0700 > From: April > Subject: Re: [prog] setting referer checking on in php > To: programming@linuxchix.org > Message-ID: <4304F06E.4040707@farstrider.org> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > I think it's a misleading error. HTTP_REFERER can be spoofed or left > unset by a browser, so it's unlikely that not having that data would > make the script fail silently. Would you be willing to send the > formmail.php file? It could be failing for any number of reasons, but > my guess is it's because register_globals went from on to off (likely > if > you upgraded PHP from pre-4.2). > > If it DID stop working because of register_globals getting turned on, > that probably means the script is insecure and could be used by third > parties to send spam from your server. So don't just turn on > register_globals to make it work.. fix the script. > > Nicki Handy wrote: >> Hi- I've just upgraded a mac to Tiger and also upgraded the mail >> server. >> I copied the old php.ini over into the new settings but for some >> reason >> formmail.php is not working. I didn't set it up, one of the >> programmers >> I work with uses it. The error I get in the web logs says >> [PHPFormMail] HTTP_REFERER checking is turned off. >> >> So, I think this would make it fail and thus, no mail from the form. >> But >> I went into php.ini and the variable for referer is set to blank. I >> tried changing it to 1 and "on" but neither worked. Is there another >> way >> to set that? Or is that a misleading error and I do in fact have it >> turned on? I restarted the server after changing it. >> >> Thanks a lot, >> Nicki >> >> >> _______________________________________________ >> Programming mailing list >> Programming@linuxchix.org >> http://mailman.linuxchix.org/mailman/listinfo/programming >> >> >> > > > > ------------------------------ > > _______________________________________________ > Programming mailing list > Programming@linuxchix.org > http://mailman.linuxchix.org/mailman/listinfo/programming > > > End of Programming Digest, Vol 30, Issue 3 > ****************************************** > From nicki at virtualnicki.com Fri Aug 19 23:33:08 2005 From: nicki at virtualnicki.com (Nicki Handy) Date: Fri Aug 19 23:32:57 2005 Subject: [prog] setting referer checking on in php (Nicki Handy) In-Reply-To: <20050819020012.E258D2731D0@www.linuxchix.org> References: <20050819020012.E258D2731D0@www.linuxchix.org> Message-ID: <79a63648c6ebea1654e3db4ac7bd44f5@virtualnicki.com> More information: Errors I get in mail.log are postfix/qmgr[451]: long_number : from=,size=283,nrcpt=1 (queue active) postfix/qmgr[451]: long_number : to=, relay=none, delay=0, status=deferred (delivery temporarily suspended) I don't think exchange would like that from address but I don't know how it's getting created. It's not in php.ini. Also- can anyone who wants to, reply to nicki@nickihandy.com instead of or as well as the list, i'm not the journaled thing so I don't get messages til the end of the day and not sure how to change that. thanks a lot, Nicki From linuxchix at e-wire.org Thu Aug 25 17:41:13 2005 From: linuxchix at e-wire.org (Kaitlyn) Date: Thu Aug 25 18:28:18 2005 Subject: [prog] Bash script blues Message-ID: <430D7619.7040402@e-wire.org> Hi everyone, I'm having trouble with a bash script I'm tring to write. The goal of it is to clean my $HOME by moving files by type into different directories and email what it did. One the the file types are .torrents, I want them moved into a directory, marked with a "_D" infront of each one, and all the ones that are already marked with _D should be deleted. (I want to read which files are slated for deletion before they are deleted. The problem I'm having is making the spaces in the file names be replaced with an underscore. What I was trying was this: [code] for i in `ls -1 $HOUSE |grep .torrent` ; do mv "$i" `echo "$i" |sed s/\ /_/g` ; done [/code] (House is equated in the first part of the script) However I get errors: kaitlyn@rogue ~/bin/working $ for i in `ls -1 |grep .torrent` ; do mv "$i" `echo "$i" |sed s/\ /_/g` ; done mv: cannot stat `this': No such file or directory mv: cannot stat `is': No such file or directory mv: cannot stat `torrent.torrent': No such file or directory kaitlyn@rogue ~/bin/working $ ls this is torrent.torrent kaitlyn@rogue ~/bin/working $ I'm fairly sure the problem is that is breaks on spaces, but I'm not sure how to make it not break on spaces, google didn't have any answers that I could find, and I've spent about 45 minutes trying to make it work. Not too sure what to do, so I thought I'd email this list to see if anyone has any ideas? --Kaitlyn From jarich at perltraining.com.au Thu Aug 25 19:13:13 2005 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Thu Aug 25 19:13:20 2005 Subject: [prog] Bash script blues In-Reply-To: <430D7619.7040402@e-wire.org> References: <430D7619.7040402@e-wire.org> Message-ID: <430D8BA9.9000306@perltraining.com.au> Kaitlyn wrote: > However I get errors: > kaitlyn@rogue ~/bin/working $ for i in `ls -1 |grep .torrent` ; do mv > "$i" `echo "$i" |sed s/\ /_/g` ; done > mv: cannot stat `this': No such file or directory > mv: cannot stat `is': No such file or directory > mv: cannot stat `torrent.torrent': No such file or directory > kaitlyn@rogue ~/bin/working $ ls > this is torrent.torrent > kaitlyn@rogue ~/bin/working $ If you want a solution to make the problem away I can help you with that. If you want to know why your above code isn't working, I can't help so much. If you try: for i in `ls -1 | grep .torrent`; do echo "$i"; done; you'll find that what the for loop is giving you is this foo it.torrent this_that_torrent.torrent which isn't a good thing at all. I don't know how to make the for loop behave itself. I also can't make: echo "$i" | sed s/\ /_/g work when I provide my own string, but I don't know how to fix that either. Anyway, if you want a useable solution I can certainly help. For a pure perl solution try: perl -e 'use File::Copy; foreach(<*.torrent>) {$newname = $_; $newname =~ s/ /_/g; move($_, $newname); }'; If you want a slightly more bash-ish solution we could do: perl -e 'for(<*.torrent>) {$nn = $_; $nn =~ s/ /_/g; system("mv", $_, $nn"); }'; I'm sorry I can't actually help you with the bash issue though. All the best, Jacinta -- ("`-''-/").___..--''"`-._ | Jacinta Richardson | `6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia | (_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 | _..`--'_..-_/ /--'_.' ,' | contact@perltraining.com.au | (il),-'' (li),' ((!.-' | www.perltraining.com.au | From dan at cellectivity.com Thu Aug 25 19:33:05 2005 From: dan at cellectivity.com (Dan) Date: Thu Aug 25 19:45:43 2005 Subject: [prog] Bash script blues In-Reply-To: <430D7619.7040402@e-wire.org> References: <430D7619.7040402@e-wire.org> Message-ID: <1124962385.12519.14.camel@localhost.localdomain> > for i in `ls -1 $HOUSE |grep .torrent` ; do mv "$i" `echo > "$i" |sed s/\ /_/g` ; done The problem is in the "for" statement. The `ls -l ...` is evaluated to to the string "this is torrent.torrent", which is then split at each space. The solution is to write it like this: for i in $HOUSE/*.torrent ; do ... By the way, the statement looked correct to me as well. I had to do some serious debugging to find the problem. -- I'm an idiot. At least this one [bug] took about 5 minutes to find. - Linus Torvalds From linuxchix at e-wire.org Thu Aug 25 20:16:44 2005 From: linuxchix at e-wire.org (Kaitlyn) Date: Thu Aug 25 20:17:20 2005 Subject: [prog] Bash script blues In-Reply-To: <1124962385.12519.14.camel@localhost.localdomain> References: <430D7619.7040402@e-wire.org> <1124962385.12519.14.camel@localhost.localdomain> Message-ID: <430D9A8C.4050203@e-wire.org> Thanks Dan and Jacinta! That part of it is working now, and I'm a very happy camper. I went with the for over the perl because perl scares me. I have a friend who is like a genus with it, and I just can't pick it up. Also, Dan I didn't know you could do that! I'm used to having to use back ticks in for loops "for i in `cat somefile`" or " for i in `ls somedir`" so learning that is invaluable. ^.^ Thanks again! --Kaitlyn From petzold at villa-chaos.de Thu Aug 25 20:15:57 2005 From: petzold at villa-chaos.de (Wolfgang Petzold) Date: Thu Aug 25 20:23:36 2005 Subject: [prog] Bash script blues In-Reply-To: <430D7619.7040402@e-wire.org> References: <430D7619.7040402@e-wire.org> Message-ID: <430D9A5D.3070709@villa-chaos.de> Kaitlyn: > What I was trying was this: > > [code] for i in `ls -1 $HOUSE |grep .torrent` ; do mv "$i" `echo > "$i" |sed s/\ /_/g` ; done [/code] (House is equated in the first part > of the script) > > However I get errors: > mv: cannot stat `this': No such file or directory > mv: cannot stat `is': No such file or directory > mv: cannot stat `torrent.torrent': No such file or directory Yes, I admit, that would have been my first try, too. I found that a while/read loop works with the way you collected the file names: $ ls -1 $HOUSE | grep .torrent | while read filename ; do \ mv "$filename" `echo "$filename" | sed -e 's/ /_/g;'` \ done "read var" takes a line of input from stdin and puts the line into $var. I've always found the "while read var" construction somewhat confusing, but, however, it works ... "read" seems to return an "unsuccessful" return value when it only finds an End-of-file (End-of-text, whatever) character, which will then end the "while" loop. This "while read" loop will also work if you have a file with the relevant filenames in it, say $ ls -1 $HOUSE | grep .torrent >my_files $ [find some more .torrent files] >>my_files $ while read filename ; do \ mv "$filename" `echo "$filename" | sed -e 's/ /_/g;'` \ done References: <430D7619.7040402@e-wire.org> <430D9A5D.3070709@villa-chaos.de> Message-ID: <37535.192.168.0.100.1124979627.squirrel@www.flyballdogs.com> Wolfgang Petzold said: > > $ ls -1 $HOUSE | grep .torrent | while read filename ; do \ > mv "$filename" `echo "$filename" | sed -e 's/ /_/g;'` \ > done You probably should protect the 2nd file name in case it has characters that the shell might interpret like parens, semicolons, etc: for file in *.torrent do mv "$file" "$(echo $file | tr '[:blank"] _)" done -- Kathryn http://womensfooty.com From kjh at flyballdogs.com Fri Aug 26 00:15:07 2005 From: kjh at flyballdogs.com (Kathryn Hogg) Date: Fri Aug 26 00:21:19 2005 Subject: [prog] Bash script blues In-Reply-To: <430D8BA9.9000306@perltraining.com.au> References: <430D7619.7040402@e-wire.org> <430D8BA9.9000306@perltraining.com.au> Message-ID: <39436.192.168.0.100.1124979307.squirrel@www.flyballdogs.com> Jacinta Richardson said: > If you want a solution to make the problem away I can help you with that. > If > you want to know why your above code isn't working, I can't help so much. > If > you try: > > for i in `ls -1 | grep .torrent`; do echo "$i"; done; > > you'll find that what the for loop is giving you is > > this > foo > it.torrent > this_that_torrent.torrent > > which isn't a good thing at all. I don't know how to make the for loop > behave itself. I would just do for i in *.torrent do echo $i done Which is actually better since it only matches files ending in .torrent. The original way would return every file with .torrent any where in the name. > > I also can't make: > > echo "$i" | sed s/\ /_/g echo "$i" | tr '[:blank:]' '_' should do the trick -- Kathryn http://womensfooty.com From jarich at perltraining.com.au Fri Aug 26 10:32:11 2005 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Fri Aug 26 10:32:18 2005 Subject: Learning Perl (Re: [prog] Bash script blues) In-Reply-To: <430D9A8C.4050203@e-wire.org> References: <430D7619.7040402@e-wire.org> <1124962385.12519.14.camel@localhost.localdomain> <430D9A8C.4050203@e-wire.org> Message-ID: <430E630B.7090903@perltraining.com.au> Kaitlyn wrote: > Thanks Dan and Jacinta! That part of it is working now, and I'm a > very happy camper. I went with the for over the perl because perl > scares me. I have a friend who is like a genus with it, and I just > can't pick it up. G'day Kaitlyn, If you can program in bash, you have all that it requires to learn Perl (except perhaps a good resource or three). On the resource note, you may find value in looking at the course notes we provide for free on line at: http://perltraining.com.au/notes.html These are the notes I teach from on a regular basis and most of our students have no problems at all. All the best, Jacinta -- ("`-''-/").___..--''"`-._ | Jacinta Richardson | `6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia | (_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 | _..`--'_..-_/ /--'_.' ,' | contact@perltraining.com.au | (il),-'' (li),' ((!.-' | www.perltraining.com.au |