Calling variables in case


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calling variables in case
# 1  
Old 06-12-2012
Calling variables in case

Hey guys,

I got a little problem with calling variables in my case

This is a simple version of my script:

Code:
var1=1
var2=2

while [ $1 ]
do
  case $1 in
    "a")
      var1=$var2;
      echo "1";
      echo "var1: $var1";
      echo "var2: $var2";;
    "b")
      var2=5;
      echo "2";
      echo "var1: $var1";
      echo "var2: $var2";;
  esac
  shift
done

I want the change from var2=5 to be done to var1 so that var1 also becomes 5

Is there a way to do that ?

Last edited by Scrutinizer; 06-12-2012 at 06:08 PM.. Reason: code tags
# 2  
Old 06-12-2012
not sure exactly what your asking but if you want var1=5 just add another line below var2=5.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

calling script with multiple variables in second script

Hi All, Just give me an idea on how to do the below logic. 1. I have one master script masterload.sh, the usage of this script is a. masterload.sh FULL BFLF_LOAD.txt b. masterload.sh DELTA TDLD_LOAD.txt c.masterload.sh USER MAS_LOAD.txt FULL , DELTA ,USER are the varaibles based... (1 Reply)
Discussion started by: mora
1 Replies

2. Shell Programming and Scripting

[Solved] Change Upper case to Lower case in C shell

Is there a command that can switch a character variable from UPPER case to lower case? like foreach AC ( ABC BCD PLL QIO) set ac `COMMAND($AC)` ... end Thanks a lot! (3 Replies)
Discussion started by: rockytodd
3 Replies

3. Shell Programming and Scripting

calling function with case

Hi I making a shell script and have some problem to start a function. echo "chose a number to download" read i; case $i in 1) head -1 ~/test3 | tail -1 > ~/test4;; 2) head -2 ~/test3 | tail -1 > ~/test4;; 3) head -3 ~/test3 | tail -1 >... (9 Replies)
Discussion started by: pelle
9 Replies

4. 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

5. Shell Programming and Scripting

problems calling out variables in a loop

good afternoon forums. i have a problem that ive been trying to work out all morning and cant seem to get my head around it. what i have in my script is individual letters saved in different variables. so if the word unix was saved then 'u' would be stored in the variable 'wvar1' 'n' in 'wvar2'... (7 Replies)
Discussion started by: strasner
7 Replies

6. Shell Programming and Scripting

passing a variables value from the called script to calling script using ksh

How do i get the value of the variable from the called script(script2) to the calling script(script1) in ksh ? I've given portion of the script here to explain the problem. Portion of Script 1 ============= ----- ----- tmp=`a.ksh p1 p2 p3` if then # error processing fi -----... (10 Replies)
Discussion started by: rajarkumar
10 Replies

7. Shell Programming and Scripting

Script needed to select and delete lower case and mixed case records

HELLO ALL, URGENTLY NEEDED A SCRIPT TO SELECT AND DELETE LOWER AND MIXED CASE RECORDS FROM A COLUMN IN A TABLE. FOR EXAMPLE : Table name is EMPLOYEE and the column name is CITY and the CITY column records will be: Newyork washington ... (1 Reply)
Discussion started by: abhilash mn
1 Replies

8. UNIX for Dummies Questions & Answers

lower case to upper case string conversion in shell script

How can convert a Lower case variable value to an upper case in the kron shell script. (3 Replies)
Discussion started by: dchalavadi
3 Replies

9. UNIX for Dummies Questions & Answers

variables use upper case? sed : output to the same file?

Hi, Q1: are the variables in shell script usually UPPER CASE? Q2: can sed output to the same file that it's using it? eg. cat sameFile | sed 's/here/there/g' > sameFile ? I expect the sed replace all "here" to "there" and change it in sameFile. i tried that one, the sameFile... (1 Reply)
Discussion started by: gusla
1 Replies
Login or Register to Ask a Question