#!/bin/bash
# shell命令先于Perl脚本执行
echo "This precedes the embedded Perl script within \"$0\"."
echo "==============================================================="
perl -e 'print "This line prints from an embedded Perl script.\n";'
# 像sed命令一样,Perl使用'-e'选项
echo "==============================================================="
echo "However, the script may also contain shell and system commands."
exit 0
#!/bin/bash
# bashandperl.sh
echo "Greetings from the Bash part of the script, $0."
# 这里可以写更多的Bash命令
exit
# Bash脚本部分结束
# =======================================================
#!/usr/bin/perl
# 这部分脚本要像下面这样调用
# perl -x bashandperl.sh
print "Greetings from the Perl part of the script, $0.\n";
# Perl 看起来并不像 “echo” ...
# 这里可以写更多的Perl命令
# Perl命令部分结束
bash$ bash bashandperl.sh
Greetings from the Bash part of the script.
bash$ perl -x bashandperl.sh
Greetings from the Perl part of the script.
当然还可以用shell wrapper嵌入更多的“外来户”,比如Python或者其他的...
Example 36-8. Python嵌入Bash脚本
#!/bin/bash
# ex56py.sh
# shell脚本先于Python脚本执行
echo "This precedes the embedded Python script within \"$0.\""
echo "==============================================================="
python -c 'print "This line prints from an embedded Python script.\n";'
# 并不像sed和Perl,Python使用'-c'选项
python -c 'k = raw_input( "Hit a key to exit to outer script. " )'
echo "==============================================================="
echo "However, the script may also contain shell and system commands."
exit 0