Forums: ヘルプ (Thread #36844)

read: how to have a prompt before the cursor? (2015-06-04 13:17 by mcdutchie #76277)

I'd like to display a prompt and put the cursor after the prompt for input. For instance:

printf 'Enter your name: '
read name

should produce:

Enter your name: _

(with '_' being the cursor).

This works on every shell except yash. Yash displays an inverted '$' and puts the cursor on the beginning of the next line.

Is there any way to circumvent or disable this behaviour?

Reply to #76277×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

Re: read: how to have a prompt before the cursor? (2015-06-04 20:37 by mcdutchie #76278)

[Reply To Message #76277]
> I'd like to display a prompt and put the cursor after the prompt for input.

I have since found out that the answer is to disable the "le-prompt-sp" option:

set +o le-prompt-sp

The man page does not mention that the "le-prompt-sp" also influences the behaviour of "read". This is quite confusing because the "read" command doesn't even support a prompt option.
Reply to #76277

Reply to #76278×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login