Sponsored Content
Top Forums Shell Programming and Scripting [KSH] Creating automatic variable from read input Post 302711683 by pandapowerbox on Sunday 7th of October 2012 05:15:24 PM
Old 10-07-2012
[KSH] Creating automatic variable from read input

Hello there, I am posting to seek help with a KSH script,

I am making a simple calculation program where the user can enter as many numbers as they like, I am getting their input using the read command, however I am not sure how to repeat doing this and storing the input in to new variables until the user wants the program to calculate.

Here is what I have so far

Code:
#!/bin/ksh

echo "Please input two numbers"
echo
echo "Please input value 1: "
read x1
echo
echo "Please input value 2: "
read x2

echo "The answer is: "
echo
echo "($x1 + $x2 | bc))"

I am thinking maybe using an Array is the best way to go about this, but I am really stumped on how to do this Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

creating a fixed length output from a variable length input

Is there a command that sets a variable length? I have a input of a variable length field but my output for that field needs to be set to 32 char. Is there such a command? I am on a sun box running ksh Thanks (2 Replies)
Discussion started by: r1500
2 Replies

2. Shell Programming and Scripting

Automatic Arrays in ksh

Given a line of text in ksh: string1 string2 string3 .....stringn is there a way of automatically assigning each string to an array element? Or just different variables would do. Thanks, Jon (1 Reply)
Discussion started by: Jonny2Vests
1 Replies

3. UNIX for Advanced & Expert Users

Automatic input to commands

Hi, In a shell script i am running a command which is asking for input. How can i give that automatically. I have done this before but for the time being can't recall. Was something like <| Thanks (6 Replies)
Discussion started by: vibhor_agarwali
6 Replies

4. Shell Programming and Scripting

make a variable read the value from the standard input

Hi, In Perl, how can we define a variable make it read the value from the standard input? Meaning, how can have the user type in the value that will be assigned to the variable? Thanks, (2 Replies)
Discussion started by: Pouchie1
2 Replies

5. Shell Programming and Scripting

KSH: Compare variable to $1 in an input file

Hello, I am working with KSH on AIX and I have 2 files generated from different sources... as seen below: FILE1 FILE2 AAA AAA@ABS0001C BBB BBB@ABS0003D CCC CCC@ABS0023A DDD DDD@ABC0145D EEE EEE@ABS0090A FFF FFF@ABS0002A GGG GGG@ABC0150D HHH FILE1 is main main data source,... (4 Replies)
Discussion started by: right_coaster
4 Replies

6. Shell Programming and Scripting

Automatic Input to a command

Hi, I have an issue where i run an command in a shell script. command >/dev/null ret=$? echo ret If the command returns an error i'm redirecting it to /dev/null. The prob is if an error comes it expects the user to press return to continue. And hence the return is not echoed. and the end... (4 Replies)
Discussion started by: subhrap.das
4 Replies

7. Shell Programming and Scripting

Read multiple input from CLI :ksh

Hi folks.. i got a requirement to red multiple directories from STDIN and store them to a variable. ex:- echo "Enter directory to add:" echo " Enter directory to add:" read value till there is input and when there is no input close the read loop and store variable into an array ... (1 Reply)
Discussion started by: bangaram
1 Replies

8. Shell Programming and Scripting

ksh loop to read input until QUIT

Hi I'm looking to write a simple ksh loop reading user input (and write it to a file) until the user enters QUIT at which point I want it to continue. Does anyone have an example of this type of loop? Any help much appreciated Cheers (2 Replies)
Discussion started by: Grueben
2 Replies

9. Shell Programming and Scripting

ksh to read input until QUI

Hello all I'm looking to write a simple script (ksh/sh/bsh) to read user input and write it to a file (adding each time) until the user enters QUIT at which point I'm hoping to ask some more questions. Any help much apprecited (2 Replies)
Discussion started by: Grueben
2 Replies

10. Shell Programming and Scripting

ksh - Read input from file and output CSV i same row

Hello I have the following output and want the output to look: FROM: GigabitEthernet0/0 is up, line protocol is up 1 input errors, 0 CRC, 0 frame, 1 overrun, 0 ignored 275 output errors, 0 collisions, 3 interface resets GigabitEthernet0/1 is up, line protocol is up 0... (4 Replies)
Discussion started by: JayJay2018
4 Replies
LOCALE_GET_DISPLAY_REGION(3)						 1					      LOCALE_GET_DISPLAY_REGION(3)

Locale::getDisplayRegion - Returns an appropriately localized display name for region of the input locale

	Object oriented style

SYNOPSIS
publicstatic string Locale::getDisplayRegion (string $locale, [string $in_locale]) DESCRIPTION
Procedural style string locale_get_display_region (string $locale, [string $in_locale]) Returns an appropriately localized display name for region of the input locale. If is NULL then the default locale is used. PARAMETERS
o $locale - The locale to return a display region for. o $in_locale - Optional format locale to use to display the region name RETURN VALUES
display name of the region for the $locale in the format appropriate for $in_locale. EXAMPLES
Example #1 locale_get_display_region(3) example <?php echo locale_get_display_region('sl-Latn-IT-nedis', 'en'); echo "; "; echo locale_get_display_region('sl-Latn-IT-nedis', 'fr'); echo "; "; echo locale_get_display_region('sl-Latn-IT-nedis', 'de'); ?> Example #2 OO example <?php echo Locale::getDisplayRegion('sl-Latn-IT-nedis', 'en'); echo "; "; echo Locale::getDisplayRegion('sl-Latn-IT-nedis', 'fr'); echo "; "; echo Locale::getDisplayRegion('sl-Latn-IT-nedis', 'de'); ?> The above example will output: Italy; Italie; Italien SEE ALSO
locale_get_display_name(3), locale_get_display_language(3), locale_get_display_script(3), locale_get_display_variant(3). PHP Documentation Group LOCALE_GET_DISPLAY_REGION(3)
All times are GMT -4. The time now is 02:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy