problem using bash variables with command-line perl in bash script

From: Marcus Claesson (m.claesson_at_student.ucc.ie)
Date: 11/27/03


To: beginners@perl.org
Date: 27 Nov 2003 18:04:15 +0000

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
argument, which is a file name, exists on the same line in the file
updated_files.txt.

#!/bin/bash
FILENAME=$1
UPDATED=`date +%F`
echo
echo "perl -wne 'if (/$FILENAME/) { s/\d{4}-\d{2}-\d{2}/$UPDATED/;print;
} ' updated_files.txt" #Exactly as below, to see how the command looks
like

perl -wne 'if (/$FILENAME/) { s/\d{4}-\d{2}-\d{2}/$UPDATED/;print; } '
updated_files.txt

exit

[marcus@neo Scripts]$ my_bash_script file1
 perl -wne 'if (/file1/) { s/\d{4}-\d{2}-\d{2}/2003-11-27/;print; } else
{ print; }' updated_files.txt

Name "main::UPDATED" used only once: possible typo at -e line 1.
Name "main::FILE" used only once: possible typo at -e line 1.

Use of uninitialized value in regexp compilation at -e line 1, <> line
1.
Use of uninitialized value in substitution (s///) at -e line 1, <> line
1.
file1 2003-10-10
Use of uninitialized value in regexp compilation at -e line 1, <> line
2.
Use of uninitialized value in substitution (s///) at -e line 1, <> line
2.
file2 2003-10-10
Use of uninitialized value in regexp compilation at -e line 1, <> line
....
....
....

But when I run what was shown in the "echo line" it works just perfectly
on the command-line. It looks like the bash variables won't follow into
the 'perl -ne' command, hence the 'Use of uninitialized value in
substitution' messages.

Does anyone know why and how I can make use of bash variables in that
perl command?

Would be very grateful for any output!

Best regards,
Marcus



Relevant Pages

  • Re: Displaying a users group memberships
    ... The user's username is passed to the script via the command line and captured with ARGV. ... I want to determine the group memberships (much like executing `groups` from the command line) and run those through a loop for processing. ... I'm very new to Perl so maybe I'm just looking for the wrong terms or something. ... The format of the command is simple: `test.pl username`, where username is a real username on the system in question. ...
    (perl.beginners)
  • Re: "register" (in perl scripts)
    ... scripted gimp. ... This is a Perl problem, not a GIMP problem so you would probably ... it looks to me like you're trying to execute a command ... By the way, your script doesn't appear to use any CGI, etc. - at ...
    (comp.graphics.apps.gimp)
  • Re: cybercafe system
    ... A simple bash script could be ran on the system which will cause it to ... text terminal after a timeout period passed in from the command line. ...
    (Ubuntu)
  • Re: Is there a way to check for an error on any command?
    ... only for the 'cp' command, but for every command executed in a script. ... We are using the bash shell, so any bash extensions, supported with bash ... cp file1 dir/file1 ...
    (comp.unix.shell)
  • Re: Linux
    ... You almost certainly have Perl already installed. ... But the actual command line interpreter should be the same between them. ... put the shebang line as the first line of the script. ... You can then execute the program ...
    (perl.beginners)