nixCraft Linux Forum

nixCraft

Linux / UNIX 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

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 18-08-2005, 07: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
  #2 (permalink)  
Old 10-03-2006, 02:01 AM
Junior Member
User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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


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 Off


Similar Threads

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


All times are GMT +5.5. The time now is 10:23 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

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 37 38