nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

print data to txt

This is a discussion on print data to txt within the Shell scripting forums, part of the Development/Scripting category; I am currently working on a PL file. where i encounter some errors. I am trying to create a dir ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 08-18-2005, 08:07 AM
rock
Guest
 
Posts: n/a
Default print data to txt

I am currently working on a PL file. where i encounter some errors.

I am trying to create a dir if it is not available :
########################

23 FILEPATH = '/trs/wg/'.$ToDate.'/'
24 print "Filepath is $FILEPATH\n";
25 if [ ! -d $FILEPATH ]
26 then
27 mkdir $FILEPATH
28 fi

########################
The error was :
Semicolon seems to be missing at printfile.pl line 25.
Semicolon seems to be missing at printfile.pl line 27.
printfile.pl had compilation errors.

Anyone can help me?
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-10-2006, 03:01 AM
Junior Member
 
Join Date: Mar 2006
Posts: 2
Rep Power: 0
crb3
Default

If by PL you mean Perl, then your IF/THEN logic needs to use Perl syntax, not Bash syntax:

23 FILEPATH = '/trs/wg/'.$ToDate.'/';
24 print "Filepath is $FILEPATH\n";
25 if ( ! -d $FILEPATH ){

27 mkdir $FILEPATH;
28 }

...Use parentheses () instead of brackets [] to enclose your condition-test statement. Use curly-braces {} to enclose your conditionally-executed block of logic, instead of the 'then' and 'fi' keywords. It is safer to conclude every statement in Perl with a semicolon, like in C, than to see which ones you can get away without (the last one in a curly-brace-enclosed block ...but does it stay the last one when you're busy editing and debugging?).

There is a curly-free way to express a simple conditional statement by flipping the order of the test and dependent-logic:

mkdir $FILEPATH unless -d $FILEPATH;

...and I use those only for simple lines I can read at a glance. (Notice that I used the 'unless' keyword, which is logically "if !" but more readable.)

fwiw
cr
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
How to print some lines from a file Prahlad Shell scripting 3 04-24-2008 12:25 AM
How to make leafpad to print satimis Linux software 0 12-25-2007 08:36 PM
Ubuntu 7.04 doesn´t print with HP K550 printer latest firmware joaquinnegrete Linux hardware 0 06-13-2007 06:31 PM
Load balancing pooling print jobs using CUPS print queues raj Getting started tutorials 0 01-16-2007 10:08 PM
Ubuntu Linux: How do I setup print quotas? cityblogger Linux software 1 07-06-2006 06:11 PM


All times are GMT +5.5. The time now is 04:40 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36