read variable after echo


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read variable after echo
# 1  
Old 05-26-2011
read variable after echo

Hi,

i want to create an user-friendly script where you are asked for two numbers. i would like that these two number to be separated with "--" for example, but i can't figure out how to do this.

for example

Code:
read -p "Insert lowest and highest value: " min ; echo -n "-- "; read max

so when i run the script

Code:
$>. script.sh
Insert lowest and highest value: 4 -- 10

instead, i get

Code:
$>. script.sh
Insert lowest and highest value: 4
-- 10

i would like the user to insert all the variables in the same line

any help is appreciated
thanks
# 2  
Old 05-26-2011
Code:
$ read -p 'Insert lowest and highest value: ' min max
Insert lowest and highest value: 3 6
$ echo $min $max
3 6

# 3  
Old 05-26-2011
You've got 2 read statements with an echo between them. Putting them on the same line in the script won't make them behave as a single read.
You'll have to read the entire "min -- max" line in a single read and then parse it to get your values.
# 4  
Old 05-27-2011
Ok. Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to echo a value of a var stored in another variable?

I'm writing a shell script in AIX and using ksh. I have a scenario where I have a variable A which stores $B. so when i echo "$A" it prints $B But I wish to print value stored in var b ie. \a\dir\res\ I wish to store \a\dir\res\ in a third variable C. later I want to cd into that path :... (1 Reply)
Discussion started by: simpltyansh
1 Replies

2. Shell Programming and Scripting

How to read in a part of an echo line?

Hello, I have a very basic script #!/usr/bin/ksh while print ' ' print ' 1. View Command History ' print ' 2. List files in current Directory ' read opt'?Enter Option> ' ;do if ;then fc -l fi # if ;then ls -la I want to... (10 Replies)
Discussion started by: Grueben
10 Replies

3. Shell Programming and Scripting

echo the NAME of the variable

#!/bin/bash varA="AAA1" varB="BBB2" varC="CCC3" for proccx in $varA $varB $varC do echo "the current name is ????? , the value is $proccx" echo " " done #end of script I want the output to look something like this: the current name is varA, the value is AAA1 the current name is... (5 Replies)
Discussion started by: ajp7701
5 Replies

4. UNIX for Dummies Questions & Answers

How to assign echo in variable

I've testing the following code: echo test.txt | cut -d . -f1and get the output "text" So why can't i assign the command to a variable? VAR='"echo test.txt | cut -d . -f1"' echo $VAR (5 Replies)
Discussion started by: jl487
5 Replies

5. UNIX for Dummies Questions & Answers

echo appends to a read-only file

echo command can append to a read-only file too. If the file is read-only, with w flag removed, then even echo should not be able to append to the file. But it is possible. Can anybody explain the below behaviour? /root > echo 'sample text' > file /root > cat file sample text /root >... (2 Replies)
Discussion started by: anand_bh
2 Replies

6. Shell Programming and Scripting

While read do, then echo, gives double output

Sorry about the title, but this should be fairly self-explanatory. My script seems to work, except that in the output, below, the first three lines are correct, but why does it print the additional lines 4, 5, & 6? Script: #!/bin/bash while read; do client="$(grep -m 1 Client | awk... (3 Replies)
Discussion started by: MrKen
3 Replies

7. Shell Programming and Scripting

how to read a file to an echo statement

I was searching for an option where i can echo some strings together with the contents of a file. Eg. I was to echo the below string to a file "alter application PMS_ add variable CurrYear Y2009;" >> ${ESS_MAXL_DIR}/PMS_SUB.txt The value 2009 is coming from a file called date.txt without the... (3 Replies)
Discussion started by: Celvin VK
3 Replies

8. Shell Programming and Scripting

assigning variable value using echo

I am modifying an existing script and it has the following line: export SomeEnvVar=`echo ${SomeLocalVar}` Why wouldn't it just read: export SomeEnvVar=${SomeLocalVar} Is there some reason to use echo instead of a direct assignment? :confused: (2 Replies)
Discussion started by: shellburger
2 Replies

9. Shell Programming and Scripting

echo variable problem

hi I have say five variable. I would ask the user which one they want me to print and then print accordingly. TEST_1='10.2.3.4' TEST_2='11.2.3.5' TEST_3='12.2.3.5' TEST_4='13.2.3.5' TEST_5='14.2.3.5' print_var() { echo "Accessing var num $1" echo TEST$1 #??? But How do... (6 Replies)
Discussion started by: sabina
6 Replies

10. UNIX for Dummies Questions & Answers

Display from a variable using echo.

I have a variable that is outputting a lot of space. here has been 45 lines returned ... how can I remove the spaces between the "been and the 45" CODE: fil_len=`wc -l < coshb.txt` if ; then cat coshb.txt | more echo " " echo "There has been ${fil_len} lines... (4 Replies)
Discussion started by: jagannatha
4 Replies
Login or Register to Ask a Question