How to reuse values in Shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to reuse values in Shell script
# 8  
Old 09-18-2012
You have variables val and num, both being assigned values from prior portions of your script. Now you want to read sth., and either keep the before-assigned value, when the user just presses <enter>, or assign your variable a new value. Do so reading into a third, temporary variable like tmp, and don't touch val or num if tmp is empty. This is what I posted in #4, put in plain english.
# 9  
Old 09-18-2012
Do
Code:
echo "Enter Value : \c" ; read val
echo "Enter number: $val\c" ; read num
if [ "$num""X" = "X" ]; then  # or use: if [ -z "$tmp" ];... if possible
  num="$val"
fi
echo $val
echo $num

# 10  
Old 09-19-2012
I tried with the script as you suggested..
Enter Value : 12
Enter number: 12
val: 12, num:

For the 2nd argument I just press the enter but null value has been passed.

Actually earlier I wanted to re-use the same value but later the request has been changed that's why I asked you for that to either re-use or edit the value.

Thanks.

---------- Post updated at 09:29 PM ---------- Previous update was at 09:18 PM ----------

Hi 244an

Thanks for your time and reply.

I tried with the script as you suggested but I am not able to edit value for 2nd argument. Please see the output.

Enter Value : 12
Enter number: 1234
12
34
After change it to another condition as suggested by you... and the output was

Enter Value : 12
Enter number: 1234
12
12

Thanks.

---------- Post updated 19-09-12 at 04:03 PM ---------- Previous update was 18-09-12 at 09:29 PM ----------

Anyone there to help me out. Thanks.
# 11  
Old 09-19-2012
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.
# 12  
Old 09-19-2012
What you exact want...?

give some the details..

for inputs what your output should be..

Code:
val="" and val=25#any number
num="" and num=14#any number

# for above inputs, combine those inputs and give your desired output

# 13  
Old 09-19-2012
Hi Pamu

Thanks for you reply.

Here is my requirement.

echo "Enter Serial Number :\c" ; read SNO
echo "Enter Value :\c" ; read VAL

There are 2 types of condition
1. If I want to use the same number for variable VAL (reuse the value of SNO) so it will display there like
echo "Enter Value : $SNO \c" ; read VAL
2. If I want to enter new number (VAL), so in this case need to remove the displayed value from there and enter new number.

Thanks.
# 14  
Old 09-19-2012
Quote:
Originally Posted by SushilAnand
echo "Enter Serial Number :\c" ; read SNO
echo "Enter Value :\c" ; read VAL

There are 2 types of condition
1. If I want to use the same number for variable VAL (reuse the value of SNO) so it will display there like
echo "Enter Value : $SNO \c" ; read VAL
2. If I want to enter new number (VAL), so in this case need to remove the displayed value from there and enter new number.
You want to display this....

Code:
Enter Value : $SNO \c  # if you want to use same number
and
Enter Value :  \c # If you want to use new number

Let me know if i m incorrect..?
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 pass values to a script called from within another script in shell?

Ceiling Light - The Forgotten Element One of the highest details concerning using an LED ceiling panel essentially offer a fantastic dance floor which definitely makes the customers dance right away.They are a quite low cost method of something like a lighting solution, simple collection up,... (1 Reply)
Discussion started by: harveyclayton
1 Replies

2. UNIX for Beginners Questions & Answers

How to pass values to a script called from within another script in shell?

Need ideas on how to achieve the below. We have a script say "profile.sh" which internally calls another existing script called "name.sh" which prompts for the name and age of a person upon execution. When i run profile.sh how can i populate a pre-defined value from another file and pass that... (1 Reply)
Discussion started by: sankasu
1 Replies

3. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

4. Shell Programming and Scripting

Shell script to sum every 3 values

I am looking for an easy way to calculate the sum of three values (*-12, *-01, *-02) which are contained after a comma (,). I have found an awk command that will sum every 3rd value, but I am not interested in the values before the comma (,). awk '{s+=$1}NR%3==0{print s;t+=s;s=0}'I am only... (8 Replies)
Discussion started by: ncwxpanther
8 Replies

5. Shell Programming and Scripting

how to reuse a shell script to change env from perl

Hi: I am trying to reuse an existing shell script foo1.csh to set environment variables inside a perl script and its childern processes. Is it possible at all to make those environment variables persistent in the main perl process and its children processes? Do I have to create a new... (4 Replies)
Discussion started by: phil518
4 Replies

6. Shell Programming and Scripting

How to get values from an excel in a shell script

Hi All, Am trying to write a shell script which will get values from an excel and do some calculations. Can any one pls help me out in the commands used to get the values from ms-excel. Thanks!!!:) (2 Replies)
Discussion started by: msri.1900
2 Replies

7. Shell Programming and Scripting

need help on shell script(to pass the values)

only the arguments that are written to the file, my script is (sh /u01app/wkf.sh"$start_no","$name","$Condition","$file_name") like that when ever I run my script I need to write into a new file every time, like wise I have upto10 files with different names.bec my $start_no and $name will... (1 Reply)
Discussion started by: sai123
1 Replies

8. Shell Programming and Scripting

Shell Script: want to insert values in database when update script runs

Hi , I am new to linux and also also to shell scripting. I have one shell script which unpacks .tgz file and install software on machine. When this script runs I want to insert id,filename,description(which will be in readme file),log(which will be in log file) and name of unpacked folder... (1 Reply)
Discussion started by: ring
1 Replies

9. Shell Programming and Scripting

Values of value($$X) in unix shell script

Values of value of x ($$X) in unix shell script program ---------------- #!/bin/ksh t1='/CPI/nodeA/stubs/Test/T1' t2='/CPI/nodeA/stubs/Test/T2' cd $$1--> Parameter may me t1 or t2 ------------------- expecting cd $t1 shold go to the path but it is giving error. (5 Replies)
Discussion started by: ganesh_111
5 Replies

10. Shell Programming and Scripting

Returning Values (shell Script)

I have an application on Informix 4GL, and I am invoking the shell script from the program, but I need to know if the shell script work fine or not, in order to continue the process. I know that we can use $? to get the final status but this is on unix command. How can I return a value from the... (3 Replies)
Discussion started by: jennifer01
3 Replies
Login or Register to Ask a Question