简体   繁体   中英

Shell script to automate the installation of cpan modules

I am writing a shell script to automate the installation of cpan (Comprehensive Perl Archive Network) modules.

#!/bin/bash
perl -MCPAN -e shell
o conf make_arg -I/"$PWD"
o conf make_install_arg -I/"$PWD"

The first command is being executed and it enters into the cpan shell, but the later commands are not detected. I think the later commands are not being executed as it is a different shell. Any leads on this is appreciated.

Thanks.

You are writing a bash script, and o conf .... is not a bash command.

You could remote control the CPAN shell, by either

  • providing all the input in a file, from where you redirect the stdin, ie perl -MCPAN -e shell <my_commands.txt . Note that this will fail, if the CPAN shell clears the input buffer after each command (I don't think that it does, but it could be).

  • Write a expect script

  • Use your favorite programming language and use the Telnet protocol to steer the CPAN shell; since this is about Perl, you could use Perl's Net::Telnet module.

  • Since the CPAN shell is written in Perl, I guess you can also write the whole thing completely in Perl, using the features which already there in the CPAN module. I would start by looking at the source code of the CPAN module to study, how the commands (for instance conf ) are handled in Perl. After all, the CPAN shell is only one of the features of this module, although this is of course the one which people usually use.

Use bash here documents . Your script will look something like this:

#!/bin/bash
perl -MCPAN -e shell <<END_OF_CPAN_COMMANDS
o conf make_arg -I/"$PWD"
o conf make_install_arg -I/"$PWD"
END_OF_CPAN_COMMANDS

You can add more commands before the final END_OF_CPAN_COMMANDS .

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