Re: [SLUG] my next stupid question
On Tue, 3 Jul 2001, Alister Waller wrote: for i in `ls *.TXT` ALister, as in the last question, you dont seem to be aware that wildcard expansion is done by the shell, not by the command as in MS-DOS. So the 'ls' does nothing useful, and may cause errors. Shells are complex, and worth reading about. -- Mike Holland [EMAIL PROTECTED] --==-- -- SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug
[SLUG] my next stupid question
Hi, another stupid question. I am running a script from a cronjob. part of the script is a for loop. see below: for i in `ls *.TXT` do cat $i newfilename mv $i /tmp done Now, if there are no *.TXT files then I get an error sent back to the owner of the crontab file. I don't want to see this error. I know I could remove the errors at the cronjob level but there are other errors in the script I might want to see. I just don't care if there is nothing listed for the loop to function. regards Alister -- SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug
Re: [SLUG] my next stupid question
quote who=Alister Waller for i in `ls *.TXT` do cat $i newfilename mv $i /tmp done Why cat? cp $i newfilename would do pretty well. Now, if there are no *.TXT files then I get an error sent back to the owner of the crontab file. 2 /dev/null If you're not interested in the stderr output of the loop, put the entire loop in parentheses and direct stderr to /dev/null from it. - Jeff -- For a list of points detailing how technology has failed to improve our lives, please press 3. -- SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug
Re: [SLUG] my next stupid question
On Tue, Jul 03, 2001 at 02:23:44PM +1000, Alister Waller wrote: another stupid question. No such thing. :-) I am running a script from a cronjob. part of the script is a for loop. see below: for i in `ls *.TXT` do cat $i newfilename mv $i /tmp done Now, if there are no *.TXT files then I get an error sent back to the owner of the crontab file. A fairly common idiom for this is: fileList=`echo *.TXT` if [ $fileList != '*' ]; then ...(insert other stuff here) fi That should do what you want. Cheers, Malcolm -- Monday is an awful way to spend 1/7th of your life. -- SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug
Re: [SLUG] my next stupid question
On Tue, Jul 03, 2001 at 02:33:19PM +1000, Jeff Waugh wrote: quote who=Alister Waller for i in `ls *.TXT` do cat $i newfilename mv $i /tmp done Why cat? cp $i newfilename would do pretty well. he's got a there, not a , so cp $i newfilename isn't the same :). a better solution would probably be: for i in *.TXT; do cat $i newfilename mv $i /tmp done (1) you can just do *.TXT; no need for `ls *.TXT`. (2) the checks the error code returned by cat, so that the mv is only done if there was no errors. Now, if there are no *.TXT files then I get an error sent back to the owner of the crontab file. 2 /dev/null ie ( for i in *.TXT; do cat $i newfile mv $i /tmp; done ) 2 /dev/null to make Jeff's last comment completely unambigious :) (can you replace the () with {} for that loop? not sure if you can redirect the entire loop to /dev/null if you don't run a subshell.) -- #ozone/algorithm [EMAIL PROTECTED] - trust.in.love.to.save -- SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug
Re: [SLUG] my next stupid question
On Tue, Jul 03, 2001 at 02:33:19PM +1000, Jeff Waugh wrote: quote who=Alister Waller for i in `ls *.TXT` do cat $i newfilename mv $i /tmp done Why cat? cp $i newfilename would do pretty well. No it wouldn't. Note the `'. Now, if there are no *.TXT files then I get an error sent back to the owner of the crontab file. Try this: cat *.TXT newfilename 2/dev/null mv *.TXT /tmp 2/dev/null Or even: (cat *.TXT newfilename mv *.TXT /tmp) 2/dev/null Note that this will create `newfilename' even if there are no files matching `*.TXT'. Cheers, John -- whois [EMAIL PROTECTED] -- SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug
Re: [SLUG] my next stupid question
quote who=Andre Pang he's got a there, not a , so cp $i newfilename isn't the same :). Alister pointed that out too. The 'newfilename' threw me. ;) - Jeff -- Can we have a special TELSABUG category, and everything gets dropped to fix them first? - Telsa Gwynne -- SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug
RE: [SLUG] my next stupid question
The parentheses did it, thanks Jeff and co. 2 /dev/null If you're not interested in the stderr output of the loop, put the entire loop in parentheses and direct stderr to /dev/null from it. - Jeff -- For a list of points detailing how technology has failed to improve our lives, please press 3. -- SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug -- SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug
Re: [SLUG] my next stupid question
On Tue, Jul 03, 2001 at 12:52:33PM +0800, Malcolm Tredinnick wrote: A fairly common idiom for this is: fileList=`echo *.TXT` if [ $fileList != '*' ]; then ...(insert other stuff here) fi Doh! I didn't actually run this, obviously. The 'if' clause should be if [ $fileList != '*.TXT' ]; then (etc...) Malcolm -- No one is listening until you make a mistake. -- SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug