Prompting user twice on the same line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Prompting user twice on the same line
# 8  
Old 01-12-2015
As you might have seen from the previous answers (which are all, more or less, glorious hacks) what you want is impossible directly. The reason is that the terminal a typical UNIX session uses is linebased: you enter a command, which prints one or more lines, then you enter the next command.

A UNIX terminal is in principle like an endless roll of paper with a typing device to print on it, like a classic typewriter. In fact the typical "tty"s - "teletypes" - commonly in use when UNIX was created were exactly this: typewriters connected to a computer via a serial line. Modernization put layer on layer of virtualization and abstraction onto this but the basic principle remained.

It is possible to get a little more than that, but that depends on the terminal you use: enter

Code:
# echo $TERM

and you probably get an output like "xterm", "dtterm", "kterm", or similar. These (rather modern, compared to when the terminal system of UNIX was designed) terminals can do more fancy things like reposition the cursor (search for the terms "termcap" and "terminfo" to get more information about how that works), print in various colours and more.

The way they do that is quite unwieldy, though (see the previous posts). This is why this part (the ugly part of the coding) is put away into libraries which can nicely be used from the commandline: the most common library and a de-facto standard in itself is "curses", which i suggest you try to install and use.

If you are interested in using a grahical (instead of text-oriented) tool you could also give "Tcl" with the "Tk" extension a try. "Tcl/Tk" (usually pronounced "tickle-teekay") is a very common and widely used tool for developing GUI-oriented programs. As a scripting language it is relatively easy to learn (about as complicated as shell programming).

I hope this helps.

bakunin
# 9  
Old 01-12-2015
Again a bit of a kludge but as I use tput it should work for other terminal types (eg wyse), the escape sequences hard-coded in previous solutions are specific to VT* compatible terminals.

Note it also works for 2 digit and longer numbers.

The first line ensures the prompt isn't on the bottom line by printing a blank line and then going up.

Code:
printf "\n"; tput cuu 1
printf "Enter the two digits of your sum: "
tput sc
read NUM1
tput rc
read -p "$NUM1 + " NUM2
echo "$NUM1 + $NUM2 = $((NUM1 + NUM2))"

edit: use read -d" " NUM1 to use space instead of CR between 1st and 2nd number

Last edited by Chubler_XL; 01-12-2015 at 10:50 PM..
This User Gave Thanks to Chubler_XL For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

SFTP without prompting password

Dear unix experts, i have a requirement as below. i need to use SFTP as FTP. ftp -n -v << ENDFTP open test_ftp.server user ftp_user_name ftp_password quit ENDFTP if i use this in a shell script, it's not asking for password. But i want the similar thing achived using... (5 Replies)
Discussion started by: AraR87
5 Replies

2. Shell Programming and Scripting

Reading ls -l output line by line awk the user name and su user to run commands

Using ksh on AIX what I am trying to do is to read the ls -l output from a file in a do while loop line by line. Extract the user name(3rd field) and the directory/file name(9th field) using awk and save them into variables. su -c to the user and change directory/file permisions to 777. Script I... (13 Replies)
Discussion started by: zubairom
13 Replies

3. Shell Programming and Scripting

Ssh is prompting for password

Hi, When i am trying to connect to other server using ssh coomand, it is prompting for password. But i want to hardcode it with username so that it should not prompt for password. And i dont want to use "ssh-keygen" method as it is not allowed. Please help me. Regards, Mukta (7 Replies)
Discussion started by: Mukta
7 Replies

4. Shell Programming and Scripting

Prompting for password

Hi, I have SVN installed in my UNIX solaris server. I actually automated the process that downloads code from SVN server to UNIX solaris server in script. When i run the script, its asking for password to download every element. Its really difficult to type password for every element when... (3 Replies)
Discussion started by: gthangav
3 Replies

5. Shell Programming and Scripting

su through normal user prompting for password.

I have two users on linux box, say user1 user2.Both the users are having passwords. Now I would like to run the script from user1 and switch to another user i.e., user2 from the script itself. ** I do have limited access and I am running from the normal user account.Not from the root... (2 Replies)
Discussion started by: giridhar276
2 Replies

6. Shell Programming and Scripting

Prompting for file deletion?

I got help in another forum but now I need further help so I figured I'd ask here. I had to write a script to delete certain filenames of certain size. I got this far.. find . -size 110c -name "*testing*" -print | xargs -n 1 rm -i It finds the correct files, but the prompts to delete are all... (2 Replies)
Discussion started by: NycUnxer
2 Replies

7. UNIX for Dummies Questions & Answers

sftp prompting for password

I have the problem with SFTP; BELOW IS the entry from my ssh_config file It's prompting me for password all the time when using SFTP. pLEASE help. (1 Reply)
Discussion started by: dsravan
1 Replies

8. UNIX for Advanced & Expert Users

SSH - Prompting for password

Hi, Can anybody tell me a way to do ssh , without prompting for password from keyboard, Using RSA. The requirement is I need to create the key , using passphrase also..... Is there any way to do it in UNIX ? I am doing it from AIX machine , but remote machine is Linux I tried... (8 Replies)
Discussion started by: shihabvk
8 Replies

9. UNIX for Dummies Questions & Answers

prompting for account that expired

I have this problem. Two accounts in an aix. Account A expired and it would auto prompt for new password when the user failed to log in, but Account B would not prompt for the new password. Instead it will only display "your account is expired. Please contact your administrator". I would like to... (1 Reply)
Discussion started by: mayyap
1 Replies

10. UNIX for Dummies Questions & Answers

not script prompting but,.............

Hi, I am writig this script and usually I have prompts like: echo "Enter file name: " read "$filename" So later when I want verify the name to something I can: if then echo "Hello $filename" Anyways how is this done without prompting for example: I have a script that manages... (3 Replies)
Discussion started by: Astudent
3 Replies
Login or Register to Ask a Question