Variable assignment question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variable assignment question
# 1  
Old 09-22-2006
Variable assignment question

Hello,

I would like to assign number of lines in a file to a variable (to be passed later as an argument to a function). I am doing it like this:

numLines=wc -l < file.txt

which gives an error. Could somebody help?
# 2  
Old 09-22-2006
Code:
numLines=$(wc -l < file.txt)

Or if using sh, do
Code:
numLines=`wc -l < file.txt`

# 3  
Old 09-22-2006
Thanks!!! It works!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable Assignment

Hi I am facing a problem. export local_folder=/opt/app/ cd /opt/app/abc/ abcversion="abc*" (abcga5 is inside /opt/app/abc/) echo $abcversion (it echoes the correct version as abcga5 ) Now when I reuse the value of abcversion for a below path: export... (6 Replies)
Discussion started by: ankur328
6 Replies

2. Shell Programming and Scripting

Same Variable Assignment

Hi I have a strange problem: In my shell script I am performing a copy task: . prop.txt cp -r $dir/ $dir/archive $dir is fetched from a property file (prop.txt) which stores its value dir=/opt/data Now the problem is another dir1 comes into picture. I only want to add... (1 Reply)
Discussion started by: ankur328
1 Replies

3. Shell Programming and Scripting

Bash variable assignment question

Suppose I have a file named Stuff in the same directory as my script. Does the following assign the file Stuff to a variable? Var="Stuff" Why doesn't this just assign the string Stuff? Or rather how would I assign the string Stuff to a variable in this situation? Also, what exactly is... (3 Replies)
Discussion started by: Riker1204
3 Replies

4. Shell Programming and Scripting

Dynamic variable assignment

My Code : -------------------------------------------- #!/bin/bash for i in `echo server1 server2` do eval ${i}_name = "apache" echo ${i}_name done -------------------------------------------- Current output : >./test.sh ./test.sh: line 5: server1_name: command not found... (3 Replies)
Discussion started by: sameermohite
3 Replies

5. Shell Programming and Scripting

Assignment with variable assigment

Hello All, I'm trying to assign integer values to variables using substitution in both the value and variable's name, i.e., number$x=$x where x is equal to one in the first assignment, two in the second assignment, and so on with x being incremented each time. However, when I do the... (7 Replies)
Discussion started by: tombombadil
7 Replies

6. Shell Programming and Scripting

'eval' used in variable assignment

pattern1=book { x=1 eval echo \$pattern$x } book (this is the output) But when I assign a variable to the output of the eval it doesn't work unless I prefix 2 times backslash before $ as shown below. { a=`eval echo \\$pattern$x` echo $a } book Why here twice "\" has to be... (3 Replies)
Discussion started by: ravisingh
3 Replies

7. Shell Programming and Scripting

Use one loop get the variable assignment

for var in {1..3} do lspci -nn |awk -v i=$var '/8086:10a7/{split($1,a,""); print "0x"a}' done it will output 0x01 0x00 0x1 I want to let bus=0x01 slot=0x00 fun=0x1, How to modify this loop? I know it can be get by bus=`lspci -nn |awk... (4 Replies)
Discussion started by: yanglei_fage
4 Replies

8. Shell Programming and Scripting

Help with variable assignment

Hi, In AIX I have a variable with , (coma) separated values assigned to it like shown below var1=apple,boy,chris i want to convert this to var1='apple','boy','chris' the number of values assigned to var1 might change and it could be from 1 to n any suggestions please? (3 Replies)
Discussion started by: rahul9909
3 Replies

9. Shell Programming and Scripting

variable assignment using awk

Guys, Could you please help me out. I need two values in two variables using awk from the o/p of grep. example:- grep sdosanjh <filename> sdosanjh myhostname myfilename NOW WHAT I WANT IS :- sdosanjh should be in variable (say NAME) myhostname should be in variable (say... (8 Replies)
Discussion started by: sdosanjh
8 Replies

10. UNIX for Dummies Questions & Answers

@ in a variable assignment

Hello Everybody, Does anyone know what the @ symbol means in a csh script, if used with a variable assignment as below @ line = 1 why not just use.... set line=1 Many thanks rkap (1 Reply)
Discussion started by: rkap
1 Replies
Login or Register to Ask a Question