简体   繁体   中英

A Perl one-liner into a bash function?

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM