LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 03: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, 03:47 AM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
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 03:49 AM.
 
Old 01-30-2014, 05:50 AM   #3
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:02 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