Initializing multiple variables in one statement


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Initializing multiple variables in one statement
# 1  
Old 11-11-2009
Initializing multiple variables in one statement

HI,
I have 5 variables var1, var2, var3, var4 and var5
I need to initialize all of them to zero.
Is there a way to do it in a single line
something like this
var1=var2=var3=var4=var5=0.
I am unable to achieve this.
What is going wrong?
# 2  
Old 11-11-2009
but you have not specified, where you are trying to do this ?

shell or perl or .... if shell, which shell ???

ok, anyway, assuming bash, and the following works.

Code:
 
$ cat t1
let var1=var2=var3=var4=var5=0
echo $var1
echo $var2
echo $var3
echo $var4
echo $var5

$ sh t1
0
0
0
0
0

# 3  
Old 11-11-2009
Thanks for the reply.
It's ksh
The solution works.
Well what if the value that i need to assign to these 5 variables is a string let's say "hello" ?
How am i supposed to do it?
If i use "let" then it gives me message as "bad number"
 
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 to apply the update statement in multiple servers on multiple dbs at a time .?

Hi , Can any please help the below requirement on all multiple servers and multiple dbs. update configuration set value='yes' ;1) the above statement apply on 31 Databases at a time on different Ip address eg : 10.104.1.12 (unix ip address ) the above ip box contains 4 db's eg : db... (2 Replies)
Discussion started by: venkat918
2 Replies

2. Shell Programming and Scripting

Assigning multiple column's value from Oracle query to multiple variables in UNIX

Hi All, I need to read values of 10 columns from oracle query and assign the same to 10 unix variables. The query will return only one record(row). I tried to append all these columns using a delimiter(;) in the select query and assign the same to a single variable(V) in unix. I thought I... (3 Replies)
Discussion started by: hkrishnan91
3 Replies

3. Shell Programming and Scripting

Reading multiple values from multiple lines and columns and setting them to unique variables.

Hello, I would like to ask for help with csh script. An example of an input in .txt file is below, the number of lines varies from file to file and I have 2 or 3 columns with values. I would like to read all the values (probably one by one) and set them to independent unique variables that... (7 Replies)
Discussion started by: FMMOLA
7 Replies

4. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

5. Shell Programming and Scripting

comparing variables in an if statement

#!/bin/bash #timetest TIMENOW="$(date)" T1=12:00:00 echo $TIMENOW >timenow cat timenow |cut -f4 -d' ' >time1 T2=$(sed -n "${1}p" time1) echo "T1 = " $T1 echo "T2 = " $T2 if then echo $T1 else echo $T2 fi I thought scripting was simple! So why does this script result in: T1 =... (4 Replies)
Discussion started by: habuchas
4 Replies

6. UNIX for Dummies Questions & Answers

variables in awk statement

Hi, i can print 2nd, 4th and 6th columns in a file using the shell command: awk -F "|" '{print $2 $4 $6}' file1.txt Now, the position and number of columns can be variable and from a variable POSLIST So let's say POSLIST='$2 $4 $6' when i use the command: a) awk -F "|" '{print... (2 Replies)
Discussion started by: ysrini
2 Replies

7. Shell Programming and Scripting

using variables in case statement

is it possible to call a variable in a case statement, for example lsmonth=Jan|Feb l |while read ans do mymonth=`echo $ans |awk '{print $6}'` case $mymonth in $lsmonth) echo do something ;; *) echo do something else ;; esac done I want to use $lsmonth... (8 Replies)
Discussion started by: gefa
8 Replies

8. Shell Programming and Scripting

Variables within a sed statement

I am just wondering if it's possible to refer to variables within a sed statement as follows:- cat $file | sed -e 1's/$oldtext/$newtext/' > $file as when I run the script, the variables are not recognised and nothing happens..?? Thanks (5 Replies)
Discussion started by: sirtrancealot
5 Replies

9. Shell Programming and Scripting

echoing two variables in one statement

I have the following -------------------- foreach var (STO SNY WKF) set ta = 5 end --------- How can I echo both variables at the same time. Something to the effect of echo ${$var}ta But this doesn't work. Seems like it would. Thanks. (4 Replies)
Discussion started by: wxornot
4 Replies

10. UNIX for Dummies Questions & Answers

How can I put wildcards in an if statement that uses variables?

With the if statement: if How can I make it so it accepts a wildcard after the ${CURR_DAY_MONTH} variable? Putting a -f /webtrends/SUN/mrw2/access.${CURR_DAY_DAY}${CURR_DAY_MONTH}* won't work, right? I think I need some kind of special character so it knows the wildcard is... (3 Replies)
Discussion started by: LordJezo
3 Replies
Login or Register to Ask a Question