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
[EMAIL PROTECTED] 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
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]