Perl & Bash

ju5t

Verified User
Joined
Sep 14, 2005
Messages
379
Location
Amsterdam
I use perl almost every day on command line level to replace certain strings in bash scripts, but until now, I never had to use bash variables. For some reason, they don't seem to work as well. Hopefully someone has a solution for the below:

Code:
#!/bin/sh

THISIP=`/sbin/ifconfig ${DEFAULTNIC} | grep 'inet addr:' | cut -d: -f2 | cut -d\  -f1`

perl -pi -e 's/# ListenIP=0.0.0.0/ListenIP=${THISIP}/' /etc/zabbix/zabbix_agentd.conf

Within the perl line, the variable is blank. What am I doing wrong?
 
use this:

Code:
export thisip=`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | cut -d\  -f1`
sed -i 's/ListenIP=0.0.0.0/ListenIP='$thisip'/' /etc/zabbix/zabbix_agentd.conf


Tested.

Regards
 
In the end it was much easier:

Code:
perl -pi -e 's/# ListenIP=0.0.0.0/ListenIP='${THISIP}'/' /etc/zabbix/zabbix_agentd.conf

I tried it without the brackets. So no need to export first.
 
Back
Top