LinuxQuestions.org
Review your favorite Linux distribution.
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
  Search this Thread
Old 01-30-2014, 04:15 AM   #1
jone kim
Member
 
Registered: Apr 2010
Posts: 185

Rep: Reputation: 16
storing the value of echo in a variable


Code:
#!/bin/bash

for i in `SOME LINUX COMMAND`
	do 
		echo "$i"
	done
how to store the value the value of i in another variable. when i did this I get the following error:
Code:
#!/bin/bash

for i in `SOME LINUX COMMAND`
	do 
		j = $(echo $i)
		echo "$j"
	done

I am getting the error "j command not found" .

why is this error coming? How to solve this?
 
Old 01-30-2014, 04:47 AM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
There must not be spaces at both sides of the '=', try
Code:
j=$(echo $i)
But also
Code:
j=$i
should work.

Also you must not put the text between 's, write
Code:
for i in SOME LINUX COMMAND
Markus

Last edited by markush; 01-30-2014 at 04:49 AM.
 
Old 01-30-2014, 06:50 AM   #3
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,493

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
But the OP wrote `SOME LINUX COMMAND` (note the backticks)
It seems that he want to use the output of a command, by iterating through the output. Therefore the output is assigned to $i.

I recommend not to use backticks but $(SOME LINUX COMMAND) instead in all cases where the output of a command is needed. For the sake of readability, backticks are confusing and can easily be overlooked.

jlinkels
 
  


Reply

Tags
shell script


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] error while storing output in variable project.linux.proj Linux - Newbie 4 02-14-2013 12:51 AM
Need help with script writing: Storing cmd in variable, print variable, then exe cmds Arodef Programming 3 01-17-2012 01:26 AM
storing a password in an environment variable irey Linux - Security 7 07-29-2011 01:35 PM
Storing table in variable DeepSeaNautilus Linux - Software 5 04-04-2009 02:45 PM
Storing part of a filename as a variable VTGuitarMan Programming 5 03-12-2008 07:47 AM


All times are GMT -5. The time now is 05:06 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration