• We did not send an email asking for donations - please read this post.

Scripting: How would you print an advisory line "at the same time" as your prompt?

CrazedNerd

Well-Known Member
Joined
Mar 31, 2021
Messages
774
Reaction score
305
Credits
6,606
I'm working on a developed script that makes looking for configuration files that may or may not be used to change something you want to change on your operating system. It starts out like this:

Code:
read -p 'Enter possible file name: ' string
echo 'To skip, just press enter.'

It would look like this when running the script, with a blinking cursor asking the user to enter something on the first line:

Code:
Enter possible file name:
To skip, just press enter.

I could make this easy by putting it all on the same line, but i'm wondering if there's a way i can execute "read" and "echo" at basically the same time so that the user sees them both at once. I'm giving the user an option to skip enter this string because there's also another factor to this search, i want to have both choices optional in terms of how this script flows.
 


JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,563
Reaction score
2,224
Credits
11,524
I’m not sure this is possible.
Maybe try something like this instead:
Bash:
echo -e "Please enter a file-name\n(or press enter to skip)"
read -p "Filename : " string

Alternatively, you could use an ncurses dialog widget. Rather than explaining it here. Take a look at this:

You could put a prompt onto the dialog and an input box and then have an "Enter" button and a "skip" button.
 
OP
CrazedNerd

CrazedNerd

Well-Known Member
Joined
Mar 31, 2021
Messages
774
Reaction score
305
Credits
6,606
I’m not sure this is possible.
Maybe try something like this instead:
Bash:
echo -e "Please enter a file-name\n(or press enter to skip)"
read -p "Filename : " string

Alternatively, you could use an ncurses dialog widget. Rather than explaining it here. Take a look at this:

You could put a prompt onto the dialog and an input box and then have an "Enter" button and a "skip" button.
It is helpful to know the limits of a programming language
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Members online


Top