LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-07-2016, 11:51 PM   #1
TashiDuks
Member
 
Registered: Sep 2010
Posts: 54

Rep: Reputation: 0
bash 'echo' displaying NULL result


I have configuration file named "mymy.conf" with following content
Code:
 "subject" : "My HTTP alert on $device.node_id"
The following script should display the value of "subject" but it displays nothing/null.

Code:
#! /bin/bash
curSubj=`grep -oP '"subject" : "\K.*(?=\$device.node_id)' .mymy.conf`
echo "$curSubj"
When i run the same syntax in terminal i.e.grep -oP '"subject" : "\K.*(?=\$device.node_id)' it displays the result as My HTTP alert on but when i run the script it does not display the result.

Is there any difference? Help Please.

Thanks

Last edited by TashiDuks; 12-08-2016 at 12:07 AM.
 
Old 12-08-2016, 12:54 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,200

Rep: Reputation: 5419Reputation: 5419Reputation: 5419Reputation: 5419Reputation: 5419Reputation: 5419Reputation: 5419Reputation: 5419Reputation: 5419Reputation: 5419Reputation: 5419
use \\ instead of \, ` will add an additional evaluation step
 
1 members found this post helpful.
Old 12-08-2016, 01:02 AM   #3
TashiDuks
Member
 
Registered: Sep 2010
Posts: 54

Original Poster
Rep: Reputation: 0
Thanks @pan64 for your response. It worked!!!

Cheers
 
Old 12-08-2016, 11:31 AM   #4
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,668

Rep: Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755
Or try $(...) instead of `...`
Normally it does not need extra escapes.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Why echo $MYVIMRC no result on debian linux? luofeiyu Linux - Newbie 4 03-12-2016 04:48 AM
[SOLVED] PHP site not displaying MySQL result pr0xibus Programming 2 06-16-2014 07:23 AM
bash -D (or bash --dump-strings) unexpected result Ubx Linux - General 2 02-24-2011 06:41 PM
excluding an echo result Msutantri Linux - Newbie 5 01-21-2010 09:16 PM
ps command displaying different result each time sugantha Linux - Newbie 2 09-12-2009 01:47 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration