pass shell variable to perl one liner

I am trying to pass shell variable to a perl one liner but it didn't work.

Am I missing something here?

export mac1
mac1=`ifconfig|grep HWaddr|gawk '{print $5}'`
perl -s -p -i -e "s/^HWADDR=.+?$/HWADDR=$mac1/g" $eth0_input

Open in new window

LVL 21
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

In what way did it not work?
What was the value of $mac1?
Which shell are you using?
MazdajaiAuthor Commented:
Mac1 has the variable but the replacement didn't happen.
I am trying to replace mac address basically.
You should first fill the variable, then export it.

Or use "export mac1=`ifconfig ... ... `"

EDIT: Please take the above just as a general hint! I just saw that in your case it should work as is.
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

$Mac1 is different from $mac1, but it looks like you are setting $mac1
Are there lines in eth0test that match /^HWADDR=.+?$/
export should not be necessary in the above shell code
MazdajaiAuthor Commented:
Was typing on my cell phone - it is mac1.
There is a line begins with the match:
Will try again when I have a chance!
No real need for perl.

mac=$(ifconfig eth0|awk '/HWaddr/ {print $NF}')
sed -i "s/^HWADDR=.*/HWADDR=$mac/" /etc/sysconfig/ifcfg-eth0

Open in new window

Note that /^HWADDR=.*/ can match where /^HWADDR=.+?$/ may not, and /etc/sysconfig/ifcfg-eth0 may not be the same as eth0test
Otherwise, there should be no difference between the sed method and the perl method

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MazdajaiAuthor Commented:
Looks like it was the regex, I thought .+? (non-greedy) is the same as .* (greedy) -  Is there a tool to troubleshoot regex / matching in perl?

Open in new window


Open in new window

Yes sed works but I am more familiar with the regex engine in Perl. I have seen issue with the regex support in GNU tools.
perl -mYAPE::Regex::Explain -e 'print YAPE::Regex::Explain->new($_)->explain for qw/^HWADDR=.*/,qw/^HWADDR=.+?$/'
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.