Bash Script read -pProblem with script substitution when running scriptError message 'source: not found' when running a script.sh file on Startup Applications isn't executedProblem with input from simple script that copies a file to a different directorybash script to run a second command with select output from first command as variableWant to write a bash script to automate creating program filesRead input for bash scriptexit a bash command in a script without exiting the scriptProper method for storing user input in bash scriptsHow to pass a value to read input before being prompted?
Global BGP Routing only by only importing supernet prefixes
Creating some gif with tikz: Any idea to get better result?
Do you "gain" 1st level?
Boss wants me to ignore a software API license
Xdebug not working over Drush
Installing Windows to flash UEFI/ BIOS, then reinstalling Ubuntu
Running code generated in realtime in JavaScript with eval()
What kind of liquid can be seen 'leaking' from the upper surface of the wing of a Boeing 737-800?
Are there any other rule mechanics that could grant Thieves' Cant?
When was "Fredo" an insult to Italian-Americans?
Doesn't the speed of light limit imply the same electron can be annihilated twice?
Did Pope Urban II issue the papal bull "terra nullius" in 1095?
What is a "soap"?
Would the USA be eligible to join the European Union?
Locked Room Murder!! How and who?
Why aren’t there water shutoff valves for each room?
A trip to the library
How does the Athlete Feat affect the Ravnica Centaur playable race?
Did DOS zero out the BSS area when it loaded a program?
(A room / an office) where an artist works
What is the hottest thing in the universe?
How far did Gandalf and the Balrog drop from the bridge in Moria?
Are there really no countries that protect Freedom of Speech as the United States does?
Weird resistor with dots around it
Bash Script read -p
Problem with script substitution when running scriptError message 'source: not found' when running a script.sh file on Startup Applications isn't executedProblem with input from simple script that copies a file to a different directorybash script to run a second command with select output from first command as variableWant to write a bash script to automate creating program filesRead input for bash scriptexit a bash command in a script without exiting the scriptProper method for storing user input in bash scriptsHow to pass a value to read input before being prompted?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm pretty sure the answer is no but I thought I'd ask anyway. I want to have a bash script with a user input that automatically proceeds after the desired amount of characters are entered, in this case 3.
So when the user enters 123 or abc, the script moves on with that variable rather than waiting for an 'Enter'.
read -p 'User Input: ' userInput
Is this possible?
bash scripts
add a comment |
I'm pretty sure the answer is no but I thought I'd ask anyway. I want to have a bash script with a user input that automatically proceeds after the desired amount of characters are entered, in this case 3.
So when the user enters 123 or abc, the script moves on with that variable rather than waiting for an 'Enter'.
read -p 'User Input: ' userInput
Is this possible?
bash scripts
add a comment |
I'm pretty sure the answer is no but I thought I'd ask anyway. I want to have a bash script with a user input that automatically proceeds after the desired amount of characters are entered, in this case 3.
So when the user enters 123 or abc, the script moves on with that variable rather than waiting for an 'Enter'.
read -p 'User Input: ' userInput
Is this possible?
bash scripts
I'm pretty sure the answer is no but I thought I'd ask anyway. I want to have a bash script with a user input that automatically proceeds after the desired amount of characters are entered, in this case 3.
So when the user enters 123 or abc, the script moves on with that variable rather than waiting for an 'Enter'.
read -p 'User Input: ' userInput
Is this possible?
bash scripts
bash scripts
edited Aug 2 at 17:09
terdon♦
72.9k14 gold badges149 silver badges233 bronze badges
72.9k14 gold badges149 silver badges233 bronze badges
asked Aug 2 at 16:01
Ashton WattsAshton Watts
252 bronze badges
252 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
In bash, you can add -n 3 or -N 3 depending on the exact behavior you require. From help read:
-n nchars return after reading NCHARS characters rather than waiting
for a newline, but honor a delimiter if fewer than
NCHARS characters are read before the delimiter
-N nchars return only after reading exactly NCHARS characters, unless
EOF is encountered or read times out, ignoring any
delimiter
If I try adding -N 3 or -n 3 it says illegal option -n.
– Ashton Watts
Aug 2 at 18:25
1
@AshtonWatts are you sure you are usingbash- notsh(ordash)?
– steeldriver
Aug 2 at 18:35
Yeah the problem was that I wasn't running it as bash. Working fine now.
– Ashton Watts
Aug 2 at 19:27
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1162955%2fbash-script-read-p%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In bash, you can add -n 3 or -N 3 depending on the exact behavior you require. From help read:
-n nchars return after reading NCHARS characters rather than waiting
for a newline, but honor a delimiter if fewer than
NCHARS characters are read before the delimiter
-N nchars return only after reading exactly NCHARS characters, unless
EOF is encountered or read times out, ignoring any
delimiter
If I try adding -N 3 or -n 3 it says illegal option -n.
– Ashton Watts
Aug 2 at 18:25
1
@AshtonWatts are you sure you are usingbash- notsh(ordash)?
– steeldriver
Aug 2 at 18:35
Yeah the problem was that I wasn't running it as bash. Working fine now.
– Ashton Watts
Aug 2 at 19:27
add a comment |
In bash, you can add -n 3 or -N 3 depending on the exact behavior you require. From help read:
-n nchars return after reading NCHARS characters rather than waiting
for a newline, but honor a delimiter if fewer than
NCHARS characters are read before the delimiter
-N nchars return only after reading exactly NCHARS characters, unless
EOF is encountered or read times out, ignoring any
delimiter
If I try adding -N 3 or -n 3 it says illegal option -n.
– Ashton Watts
Aug 2 at 18:25
1
@AshtonWatts are you sure you are usingbash- notsh(ordash)?
– steeldriver
Aug 2 at 18:35
Yeah the problem was that I wasn't running it as bash. Working fine now.
– Ashton Watts
Aug 2 at 19:27
add a comment |
In bash, you can add -n 3 or -N 3 depending on the exact behavior you require. From help read:
-n nchars return after reading NCHARS characters rather than waiting
for a newline, but honor a delimiter if fewer than
NCHARS characters are read before the delimiter
-N nchars return only after reading exactly NCHARS characters, unless
EOF is encountered or read times out, ignoring any
delimiter
In bash, you can add -n 3 or -N 3 depending on the exact behavior you require. From help read:
-n nchars return after reading NCHARS characters rather than waiting
for a newline, but honor a delimiter if fewer than
NCHARS characters are read before the delimiter
-N nchars return only after reading exactly NCHARS characters, unless
EOF is encountered or read times out, ignoring any
delimiter
answered Aug 2 at 16:05
steeldriversteeldriver
77.7k12 gold badges129 silver badges207 bronze badges
77.7k12 gold badges129 silver badges207 bronze badges
If I try adding -N 3 or -n 3 it says illegal option -n.
– Ashton Watts
Aug 2 at 18:25
1
@AshtonWatts are you sure you are usingbash- notsh(ordash)?
– steeldriver
Aug 2 at 18:35
Yeah the problem was that I wasn't running it as bash. Working fine now.
– Ashton Watts
Aug 2 at 19:27
add a comment |
If I try adding -N 3 or -n 3 it says illegal option -n.
– Ashton Watts
Aug 2 at 18:25
1
@AshtonWatts are you sure you are usingbash- notsh(ordash)?
– steeldriver
Aug 2 at 18:35
Yeah the problem was that I wasn't running it as bash. Working fine now.
– Ashton Watts
Aug 2 at 19:27
If I try adding -N 3 or -n 3 it says illegal option -n.
– Ashton Watts
Aug 2 at 18:25
If I try adding -N 3 or -n 3 it says illegal option -n.
– Ashton Watts
Aug 2 at 18:25
1
1
@AshtonWatts are you sure you are using
bash - not sh (or dash)?– steeldriver
Aug 2 at 18:35
@AshtonWatts are you sure you are using
bash - not sh (or dash)?– steeldriver
Aug 2 at 18:35
Yeah the problem was that I wasn't running it as bash. Working fine now.
– Ashton Watts
Aug 2 at 19:27
Yeah the problem was that I wasn't running it as bash. Working fine now.
– Ashton Watts
Aug 2 at 19:27
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1162955%2fbash-script-read-p%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown