LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 11-22-2010, 10:01 AM   #1
mshforever
LQ Newbie
 
Registered: Nov 2010
Posts: 7

Rep: Reputation: 1
Question Problem in assigning value to a variable in shell script.


Hi,

Why doesn't "var1=`echo $var2 | grep pattern`" work ?
Please help me.
 
Old 11-22-2010, 10:19 AM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,029

Rep: Reputation: 368Reputation: 368Reputation: 368Reputation: 368
It should. What does the command in between tickers (`) return? What ***exact*** line are you using in your script? I need to see it exactly as-is, to the last quote and punctuation character, please, copy/paste directly. Also, explain ***how*** it doesn't work. Is there an error? Is it just empty? How are you retrieving or using $var1? What's the contents of $var2?
 
Old 11-22-2010, 10:21 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,520
Blog Entries: 27

Rep: Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174
It does normally work. Can you copy and paste testing it at the command prompt, including an echo "'$var2'" before the problem variable assignment so we can see exactly what you are doing?
 
Old 11-24-2010, 12:09 PM   #4
mshforever
LQ Newbie
 
Registered: Nov 2010
Posts: 7

Original Poster
Rep: Reputation: 1
Question

Quote:
Originally Posted by i92guboj View Post
It should. What does the command in between tickers (`) return? What ***exact*** line are you using in your script? I need to see it exactly as-is, to the last quote and punctuation character, please, copy/paste directly. Also, explain ***how*** it doesn't work. Is there an error? Is it just empty? How are you retrieving or using $var1? What's the contents of $var2?
Thnks for the reply and sorry for the delay. The exact code is:

procinfo=`awk -F\\\t '/model name/{print $2}' /proc/cpuinfo`
varDual=`echo $procinfo | grep Duo`
 
Old 11-24-2010, 12:10 PM   #5
mshforever
LQ Newbie
 
Registered: Nov 2010
Posts: 7

Original Poster
Rep: Reputation: 1
Question

Quote:
Originally Posted by catkin View Post
It does normally work. Can you copy and paste testing it at the command prompt, including an echo "'$var2'" before the problem variable assignment so we can see exactly what you are doing?
Thnks for the reply and sorry for the delay. The exact code is:

procinfo=`awk -F\\\t '/model name/{print $2}' /proc/cpuinfo`
varDual=`echo $procinfo | grep Duo`
 
1 members found this post helpful.
Old 11-24-2010, 01:53 PM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,520
Blog Entries: 27

Rep: Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174
What is the output of awk -F\\\t '/model name/{print $2}' /proc/cpuinfo on your system?
 
Old 11-29-2010, 04:50 AM   #7
mshforever
LQ Newbie
 
Registered: Nov 2010
Posts: 7

Original Poster
Rep: Reputation: 1
Question

Quote:
Originally Posted by catkin View Post
What is the output of awk -F\\\t '/model name/{print $2}' /proc/cpuinfo on your system?
Thanks for the replies. I get ": Intel(R) Core(TM)2 Duo CPU E8500 @ 3.16GHz".
 
Old 11-29-2010, 05:38 AM   #8
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,202

Rep: Reputation: 1796Reputation: 1796Reputation: 1796Reputation: 1796Reputation: 1796Reputation: 1796Reputation: 1796Reputation: 1796Reputation: 1796Reputation: 1796Reputation: 1796
So then what do you get after running:
Code:
echo "$varDual"
My guess is it should be the same as:
Quote:
: Intel(R) Core(TM)2 Duo CPU E8500 @ 3.16GHz
 
Old 11-30-2010, 07:05 AM   #9
mshforever
LQ Newbie
 
Registered: Nov 2010
Posts: 7

Original Poster
Rep: Reputation: 1
Thumbs up

Quote:
Originally Posted by grail View Post
So then what do you get after running:
Code:
echo "$varDual"
My guess is it should be the same as:
Looks like the issue earlier I was getting is not appearing now. Thanks for all the replies it really helped.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Problem With Shell Script Variable Usage Crowey Linux - General 2 02-09-2010 01:03 AM
Bash/Shell: Problem using a variable in a script redvivi Linux - General 8 08-21-2008 02:02 PM
Help with variable assigning in shell scripts fultron Linux - Newbie 2 02-16-2007 04:32 PM
problem with sed n variable in shell script dipenchaudhary Programming 4 02-12-2006 10:54 PM
Assigning the output of one command to a variable (shell) guru_stew Programming 5 08-03-2003 06:12 PM


All times are GMT -5. The time now is 02:35 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration