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
# 15  
Old 09-19-2012
Quote:
Originally Posted by SushilAnand
...
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
...
Ok, the second condition you should try was wrong, should be
Code:
if [ -z "$num" ]; then

EDIT: I changed the variable names to those from the last posts in the following text:
The script (bash script, you have to change /usr/local/bin/bash to what it is on your machine), and I changed the prompt text for "VAL" for better understanding.
Code:
$ cat tfs.sh
#! /usr/local/bin/bash

echo -e "Enter Serial Number: \c" ; read SNO
echo -e "Enter Value ($SNO): \c" ; read VAL
if [ -z "$VAL" ]; then
  VAL="$SNO"
fi
echo "SNO: $SNO, VAL: $VAL"

(My OS is FreeBSD and I have to use the flag "-e" to "expand" "\c").

I don't get it what you mean is not working, the output for me is:
Code:
_$ ./tfs.sh
Enter Serial Number: 12
Enter Value (12): 34
SNO: 12, VAL: 34
_$ ./tfs.sh
Enter Serial Number: 12
Enter Value (12):
SNO: 12, VAL: 12

If you only do <return> for "VAL" it should mean the default value from "SNO", in the last example "12". As I understand you this is what you want.
There is no possibility for you to edit the default value on the screen, the read command is reading from STDIN (which echoes to the screen), _not_ from the screen, so you can never reuse the printed default value from the screen, only reuse it in the script, like I (and others) described.

NB! this is how it works on FreeBSD as far as I know.

Last edited by 244an; 09-19-2012 at 03:20 PM..
# 16  
Old 09-20-2012
Yes, you are right...
Thanks for clarify and I tried too and its working fine.

Thanks.

Last edited by SushilAnand; 09-20-2012 at 02:36 AM..
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