bourne, perl & variable question

bourne, perl & variable question

Post by Peter Seeba » Fri, 26 Aug 1994 05:02:21




Quote:>I'm trying to do the following in a Bourne shell script:
>TBLSQLFILES=`perl -ne '{ $ok=1, next if /tbl/; print $_;}' $VFILE`
>The perl prints out all lines after a certain key word is reached
>in a file.  This works excpet that I would like to replace the
>hard-coded 'tbl' to be a shell variable like this:
>TBLSQLFILES=`perl -ne '{ $ok=1, next if /$KEY/; print $_;}' $VFILE`
>But I want the other variables to continue to be interpreted by perl.
>I've already tried replacing the single quotes with double quotes
>but I get errors from perl even if I try to escape the dollar signs
>that I wish to be passed through.

The problem is that, once you're in ''s, $ signs will not be seen by the
shell.  The solution would be:
TBLSQLFILES=`perl -ne '{ $ok=1, next if /'$KEY'/; print $_;}' $VFILE`

See, sh/ksh/bash only split words on unqoted white space (and a few other
symbols, but that's not one of them.)

If $KEY can ever be more than one word, s/'$KEY'/'"$KEY"'/.

Quote:>Is there an easy answer?

Yup.

>Thanks,
>Mike


-seebs
--
Peter Seebach (aka --SeebS--)           The Laughing Prophet
signature retrovirus - modify 2 words and include in your .sig file. Oh, yeah.

 
 
 

1. Passing a variable from Bourne Shell to Perl

I am calling a shell script from perl, where the shell creates a
filename and inserts data in it. Now, I'll have to get the filename
variable from shell to perl when shell completes its execution and
returns back to perl. I want the Shell variable(filename) to print its
contents to the user.

I am having problems fetching the filename variable from shell.

Here is the snippet of my code in Perl:

system();
my $cmd= '/export/home/kanser/site/gurapay/gurapay_feed.shl';
system ($cmd) == 0 or die "Cannot run $cmd:$?\n";
my $variable_from_shell=$ARGV[0];
print "Variable form Shell is: $variable_from_shell\n";

I know the last two lines are not right. Can you please suggest me how
to proceed with this.

Thanks.

2. Bootdisk for SCSI and Ethernet

3. bourne shell variable within a variable

4. PnP modem. Now what?

5. Scope & Privacy of variables in Bourne Shell (sh)

6. xlock

7. PERL && mod_perl && FreeBSD && Apache

8. Is a boot problem in r3.1 fixed in the next release?

9. Question: Use a Perl Script to Make a Call to a Bourne Shell Script?

10. Question on variables in bourne shell code

11. Questions: bourne script call setenv & change directory

12. Problem of && || operators in bourne shelll

13. Bourne & sql & I must be doing something wrong