A Perl one-liner into a bash function?

406 Views Asked by At

Is there a way to make a perl one-liner into a bash function?

#!/bin/bash
# ~/.bashrc:
stopwatch() {
   perl -wE 'for (reverse 1..(shift)-1) {system q!clear!;open FIGLET,q!|figlet -f banner -c!;printf FIGLET "%2d:%02d",$_/60,$_%60;sleep 1}' "$1"
}

source-ing ~/.bashrc complains as follows:

  • unexpected EOF while looking for matching `''
  • syntax error near unexpected token `reverse'
  • and so on..

Usual shell wrapping works of course, but here I try to have a bash alias/function invoking perl.

There must be a way without needing to create a brand new *.pl file. Much appreciated!

1

There are 1 best solutions below

2
On

You may try to run bash and perl script together in this way as well. Moreover in your case -E is where I doubt. perl -e always works but perl -E didn't work in perl 5.8.8

See the code of combining perl with bash

#!/bin/bash
# bash_test
echo "bash commands that you wish to write"
exit 0
# End of Bash part of the script.
# =======================================================
#!/usr/bin/perl
# This part of the script must be invoked with -x option.
print "here you can use your simple system() or exec() that you might wish to use right?";
# End of Perl part of the script.