need to assign a string to a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need to assign a string to a variable
# 1  
Old 09-07-2011
need to assign a string to a variable

Hello Experts,

In my script i am using the below syntax

PHP Code:
/usr/bin/head -/opt/chumma.txt | /usr/bin/cut -" " -f3 
output of this one is --> Monday

I want to store this String in a variable (i.e) j or k...

Give me some idea experts.

Thanks in advance.
# 2  
Old 09-07-2011
Code:
var=$(ANY_COMMAND_OR_PIPE_PRINTING_TO_STDOUT)


Last edited by yazu; 09-07-2011 at 03:53 AM..
# 3  
Old 09-07-2011
Hi,

Code:
$var = `commad`;

Cheers,
RangaSmilie

Last edited by Franklin52; 09-07-2011 at 03:36 AM.. Reason: Code tags
# 4  
Old 09-07-2011
Code:
 
day=$(awk '{if(NR==1){print $3}' /opt/chumma.txt)
or
day=`awk '{if(NR==1){print $3}' /opt/chumma.txt`


# 5  
Old 09-07-2011
Quote:
Originally Posted by rangarasan
Hi,

Code:
$var = `commad`;

Cheers,
RangaSmilie
But without spaces around the "=":
Code:
var=`command`


Last edited by Franklin52; 09-07-2011 at 05:18 AM.. Reason: $ removed
# 6  
Old 09-07-2011
Quote:
Originally Posted by Franklin52
But without spaces around the "=":
Code:
$var=`command`

Do, we really need $ before var ?

Code:
 
$b=`echo "abc"`
bash: =abc: command not found

# 7  
Old 09-07-2011
Remove the preceeding $
This User Gave Thanks to Ygor For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How can I assign awk's variable to shell script's variable?

I have the following script, and I want to assign the output ($10 and $5) from awk to N and L: grdinfo data.grd | awk '{print $10,$5}'| read N L output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Discussion started by: geomarine
8 Replies

2. UNIX for Beginners Questions & Answers

Need to pass variable in a command and assign value to a variable

Hello All, Hope you're doing well ! I am trying below command to be passed in a shell script, header_date_14 is a variable and $1 is the name of a file I intend to pass as a command line argument, however command line argument is not being accepted. header_date_14=$(m_dump... (8 Replies)
Discussion started by: ektubbe
8 Replies

3. Shell Programming and Scripting

Assign a variable the nth character of a string.

I see a millioin ways to do this with echo, but what I wan to do is assign a variable the "nth" character of an incoming parameter to a ksh script. $1 will be "pia" I need to assign the first character to stmttype. (10 Replies)
Discussion started by: klarue
10 Replies

4. Shell Programming and Scripting

Problem while assign string (words with tab) to a variable

Hi, I have a String(words with tab space) in a file ->file1.txt 0xxxx 11 test $aa$ 8.43 when i read the file and assign to variable value=$(cat file1.txt) echo $value i get the output without tab spaces. 0xxxx 11 test $aa$ 8.43 How to assign string... (2 Replies)
Discussion started by: nanthagopal
2 Replies

5. Shell Programming and Scripting

Bash assign string to variable

Hi ,I am trying to assign string to variable ,but it doesn't work Also could you show me different ways to use grep,(I am trying to get the first,second and first column form file,and I am counting the chars) let name=`grep "$id" product | cut -c6-20` (25 Replies)
Discussion started by: lio123
25 Replies

6. Shell Programming and Scripting

Shell assign variable to another variable

How can I assign a variable to an variable. IE $car=honda One way I can do it is export $car=honda or let $car=2323 Is there any other ways to preform this task (3 Replies)
Discussion started by: 3junior
3 Replies

7. Shell Programming and Scripting

assign awk's variable to shell script's variable?

Dear All, we have a command output which looks like : Total 200 queues in 30000 Kbytes and we're going to get "200" and "30000" for further process. currently, i'm using : numA=echo $OUTPUT | awk '{print $2}' numB=echo $OUTPUT | awk '{print $5}' my question is : can I use just one... (4 Replies)
Discussion started by: tiger2000
4 Replies

8. Shell Programming and Scripting

How to assign the Pattern Search string as Input Variable

guys, I need to know how to assing pattern matched string as an input command variable. Here it goes' My script is something like this. ./routing.sh <Server> <enable|disable> ## This Script takes an input <Server> variable from this line of the script ## echo $1 | egrep... (1 Reply)
Discussion started by: raghunsi
1 Replies

9. Shell Programming and Scripting

read and assign each character from the string to a variable

How... can I read input by a user character by cahracter. And assign each character from the string to a variable? Any help would be greatly appreciated! Thank you! (1 Reply)
Discussion started by: Tek-E
1 Replies

10. Shell Programming and Scripting

How to assign variable from a string having blanks in between

Hi All, I am new to bash scripting. I need your help to removing spaces from a string and assign them to different variables. Iwant to call script with one command line argument which is file name which containes different attributes their type and different values eg ... (1 Reply)
Discussion started by: flextronics
1 Replies
Login or Register to Ask a Question