Ask a Question related to UNIX Programming, Design and Development.
-
Nicolas Briones #1
How to execute perl from bash
Hi everyone!
I need to trip blank spaces at begin and end on certain string.
I can do it executing
perl -e '$str = " 2003-07-29 "; $str =~ s/^\s+|\s+$//g; print $str;'
works fine!
but i need the value inside a script. So i wrote:
------------------------------
#!/bin/bash
curr_date=" 2003-07-29"
t=`perl -e "$str = \"$curr_date\"; $str =~ s/^\s+|\s+$//g; print
$str;\"`
echo $t
-------------------------------
And i get error!
i try
------------------------------
#!/bin/bash
curr_date=" 2003-07-29"
t=`perl -e "\$str = \"$curr_date\"; \$str =~ s/^\s+|\s+$//g; print
\$str;\"`
echo $t
-------------------------------
And i get error too. The problem is that i can't set perl variables
inside the -e section. The problem (it seems) how bash make diference
between script and perl variables?
Thanx!
[email]nbriones@puc.cl[/email]
Nicolas Briones Guest
-
Execute all processes in the background from bash.
I was wondering if it's possible to prepend "time" and append "&" to all commands that I execute in bash. For example I'd like $ mozilla to... -
exit perl script and cd in bash?
I've been searching the archives and google for an answer. I suspect it can't be done but thought I'd ask. What I'm trying to do is create a... -
from bash to perl; source() equivalent
(Please CC: me as I'm not yet on this list.) I have moved / am moving from bash to perl for my misc scripts. I am still at a loss as to how to... -
problem using bash variables with command-line perl in bash script
Hi! I have a problem with variables when using command-line perl in a bash script. The script should update a date (in 2003-10-10 form) if the... -
perl and bash about localization
eastcapital@hotmail.com (Mi) writes: I'm sorry, that doesn't look like real code, or at least not all of it. $cal is a variable, and unless we... -
Barry Margolin #2
Re: How to execute perl from bash
In article <208fae61.0307301249.32b584e6@posting.google.com >,
Nicolas Briones <nbriones@puc.cl> wrote:You should be using single quotes, not double quotes, just like you did>Hi everyone!
>I need to trip blank spaces at begin and end on certain string.
>
>I can do it executing
>
>perl -e '$str = " 2003-07-29 "; $str =~ s/^\s+|\s+$//g; print $str;'
>
>works fine!
>
>but i need the value inside a script. So i wrote:
>
>------------------------------
>#!/bin/bash
>
>curr_date=" 2003-07-29"
>
>t=`perl -e "$str = \"$curr_date\"; $str =~ s/^\s+|\s+$//g; print
>$str;\"`
>
>echo $t
>-------------------------------
>
>And i get error!
when you executed the command manually. Inside double quotes, $ is used to
indicate shell variables.
--
Barry Margolin, [email]barry.margolin@level3.com[/email]
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Barry Margolin Guest
-
John W. Krahn #3
Re: How to execute perl from bash
Nicolas Briones wrote:
>
> Hi everyone!
> I need to trip blank spaces at begin and end on certain string.
> I can do it executing
>
> perl -e '$str = " 2003-07-29 "; $str =~ s/^\s+|\s+$//g; print $str;'
>
> works fine!
> but i need the value inside a script. So i wrote:
>
> ------------------------------
> #!/bin/bash
>
> curr_date=" 2003-07-29"
> t=`perl -e "$str = \"$curr_date\"; $str =~ s/^\s+|\s+$//g; print $str;\"`
> echo $t
> -------------------------------
>
> And i get error!
> i try
>
> ------------------------------
> #!/bin/bash
>
> curr_date=" 2003-07-29"
> t=`perl -e "\$str = \"$curr_date\"; \$str =~ s/^\s+|\s+$//g; print \$str;\"`
> echo $t
> -------------------------------
>
> And i get error too. The problem is that i can't set perl variables
> inside the -e section. The problem (it seems) how bash make diference
> between script and perl variables?
curr_date=" 2003-07-29"
t=`perl -e's/^\s+//, s/\s+$// for $ARGV[0]; print $ARGV[0]' $curr_date`
echo $t
John
--
use Perl;
program
fulfillment
John W. Krahn Guest
-
Chris #4
Re: How to execute perl from bash
Nicolas Briones wrote:
Why are you using a bash script to run a perl one-liner? Surely it would> Hi everyone!
> I need to trip blank spaces at begin and end on certain string.
>
> I can do it executing
>
> perl -e '$str = " 2003-07-29 "; $str =~ s/^\s+|\s+$//g; print $str;'
>
> works fine!
>
> but i need the value inside a script. So i wrote:
>
> ------------------------------
> #!/bin/bash
>
> curr_date=" 2003-07-29"
>
> t=`perl -e "$str = \"$curr_date\"; $str =~ s/^\s+|\s+$//g; print
> $str;\"`
>
> echo $t
> -------------------------------
>
> And i get error!
>
> i try
>
> ------------------------------
> #!/bin/bash
>
> curr_date=" 2003-07-29"
>
> t=`perl -e "\$str = \"$curr_date\"; \$str =~ s/^\s+|\s+$//g; print
> \$str;\"`
>
> echo $t
> -------------------------------
>
> And i get error too. The problem is that i can't set perl variables
> inside the -e section. The problem (it seems) how bash make diference
> between script and perl variables?
>
> Thanx!
>
> [email]nbriones@puc.cl[/email]
make more sense to simply write the whole thing as a perl script.
#! /usr/bin/perl -w
use strict;
my $curr_date = " 2003-07-29 ";
$curr_date =~ s/^\s+|\s+$//g;
print "$curr_date\n";
Chris.
Chris Guest



Reply With Quote

