How do I start an “if” function in shell that requires the user to input between 4-9 parameters The Next CEO of Stack OverflowHow to display the Linux kernel command line parameters given for the current boot?How to exit out of the shell script successfully so that python subprocess think it is successfull exit?change the extension of all files based on user inputDisplay a line in a text file if variable matches a part in the line?Pass command line parameters to a program inside the shell scriptHow to repeat a command n times then exit?Capturing the user input without requiring “Enter”(Shell Scripting) - Modify files with user inputArguments in `bash -c mycommand arg1 arg2`How can I extract a function from bash/zsh with all its shell-related dependencies?
Why do airplanes bank sharply to the right after air-to-air refueling?
Are there any limitations on attacking while grappling?
How to count occurrences of text in a file?
How to invert MapIndexed on a ragged structure? How to construct a tree from rules?
Complex fractions
Why don't programming languages automatically manage the synchronous/asynchronous problem?
Should I tutor a student who I know has cheated on their homework?
Interfacing a button to MCU (and PC) with 50m long cable
How did people program for Consoles with multiple CPUs?
Is it ever safe to open a suspicious html file (e.g. email attachment)?
Why do we use the plural of movies in this phrase "We went to the movies last night."?
How to start emacs in "nothing" mode (`fundamental-mode`)
Is it my responsibility to learn a new technology in my own time my employer wants to implement?
Return the Closest Prime Number
Does it take more energy to get to Venus or to Mars?
Would a galaxy be visible from outside, but nearby?
I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin
How do I go from 300 unfinished/half written blog posts, to published posts?
Why has the US not been more assertive in confronting Russia in recent years?
What can we do to stop prior company from asking us questions?
How to solve a differential equation with a term to a power?
Why do professional authors make "consistency" mistakes? And how to avoid them?
Do I need to enable Dev Hub in my PROD Org?
How do we know the LHC results are robust?
How do I start an “if” function in shell that requires the user to input between 4-9 parameters
The Next CEO of Stack OverflowHow to display the Linux kernel command line parameters given for the current boot?How to exit out of the shell script successfully so that python subprocess think it is successfull exit?change the extension of all files based on user inputDisplay a line in a text file if variable matches a part in the line?Pass command line parameters to a program inside the shell scriptHow to repeat a command n times then exit?Capturing the user input without requiring “Enter”(Shell Scripting) - Modify files with user inputArguments in `bash -c mycommand arg1 arg2`How can I extract a function from bash/zsh with all its shell-related dependencies?
I needto see if between 4 and 9 arguments were entered at the command line. Then if so display the first and the third and exit with a code equal to the number of arguments on the command line
linux bash
New contributor
add a comment |
I needto see if between 4 and 9 arguments were entered at the command line. Then if so display the first and the third and exit with a code equal to the number of arguments on the command line
linux bash
New contributor
3
Since this seems semi-arbitrary, have you learned anything about UNIX shells recently that would help you along this path? What have you tried and what were the results?
– Jeff Schaller♦
2 days ago
1
Some related reading: Positional Parameters, Conditional Constructs, Bash Builtin Commands, Bourne Builtin Commands
– Jesse_b
2 days ago
add a comment |
I needto see if between 4 and 9 arguments were entered at the command line. Then if so display the first and the third and exit with a code equal to the number of arguments on the command line
linux bash
New contributor
I needto see if between 4 and 9 arguments were entered at the command line. Then if so display the first and the third and exit with a code equal to the number of arguments on the command line
linux bash
linux bash
New contributor
New contributor
New contributor
asked 2 days ago
user344036user344036
1
1
New contributor
New contributor
3
Since this seems semi-arbitrary, have you learned anything about UNIX shells recently that would help you along this path? What have you tried and what were the results?
– Jeff Schaller♦
2 days ago
1
Some related reading: Positional Parameters, Conditional Constructs, Bash Builtin Commands, Bourne Builtin Commands
– Jesse_b
2 days ago
add a comment |
3
Since this seems semi-arbitrary, have you learned anything about UNIX shells recently that would help you along this path? What have you tried and what were the results?
– Jeff Schaller♦
2 days ago
1
Some related reading: Positional Parameters, Conditional Constructs, Bash Builtin Commands, Bourne Builtin Commands
– Jesse_b
2 days ago
3
3
Since this seems semi-arbitrary, have you learned anything about UNIX shells recently that would help you along this path? What have you tried and what were the results?
– Jeff Schaller♦
2 days ago
Since this seems semi-arbitrary, have you learned anything about UNIX shells recently that would help you along this path? What have you tried and what were the results?
– Jeff Schaller♦
2 days ago
1
1
Some related reading: Positional Parameters, Conditional Constructs, Bash Builtin Commands, Bourne Builtin Commands
– Jesse_b
2 days ago
Some related reading: Positional Parameters, Conditional Constructs, Bash Builtin Commands, Bourne Builtin Commands
– Jesse_b
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
This sounds like a homework assignment, so I will give all the bits of the puzzle that you need to solve it.
- The number of arguments are kept in the special variable
$#
. - The third argument is
$3
. To see whether a variable
$var
is between 3 and 19 (inclusively), useif [ "$var" -ge 3 ] && [ "$var" -le 19 ]; then ...; fi
where
...
is the action you'd like to take if the statement is
true.Explicitly exiting from a script is done with
exit
. Explicitly returning from a function is done withreturn
. Both of these take an optional exit status.
Thank you so much it worked. I was having trouble wrapping my head around getting the range I was trying to do "$# -eq 4-9" , then I was trying to do it similar to your approach but using the -o flag.
– user344036
2 days ago
1
@user344036 If Kusalananda's answer was helpful to you, it's courteous to mark the answer as "Accepted."
– Jim L.
yesterday
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
);
);
user344036 is a new contributor. Be nice, and check out our Code of Conduct.
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%2funix.stackexchange.com%2fquestions%2f509088%2fhow-do-i-start-an-if-function-in-shell-that-requires-the-user-to-input-between%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
This sounds like a homework assignment, so I will give all the bits of the puzzle that you need to solve it.
- The number of arguments are kept in the special variable
$#
. - The third argument is
$3
. To see whether a variable
$var
is between 3 and 19 (inclusively), useif [ "$var" -ge 3 ] && [ "$var" -le 19 ]; then ...; fi
where
...
is the action you'd like to take if the statement is
true.Explicitly exiting from a script is done with
exit
. Explicitly returning from a function is done withreturn
. Both of these take an optional exit status.
Thank you so much it worked. I was having trouble wrapping my head around getting the range I was trying to do "$# -eq 4-9" , then I was trying to do it similar to your approach but using the -o flag.
– user344036
2 days ago
1
@user344036 If Kusalananda's answer was helpful to you, it's courteous to mark the answer as "Accepted."
– Jim L.
yesterday
add a comment |
This sounds like a homework assignment, so I will give all the bits of the puzzle that you need to solve it.
- The number of arguments are kept in the special variable
$#
. - The third argument is
$3
. To see whether a variable
$var
is between 3 and 19 (inclusively), useif [ "$var" -ge 3 ] && [ "$var" -le 19 ]; then ...; fi
where
...
is the action you'd like to take if the statement is
true.Explicitly exiting from a script is done with
exit
. Explicitly returning from a function is done withreturn
. Both of these take an optional exit status.
Thank you so much it worked. I was having trouble wrapping my head around getting the range I was trying to do "$# -eq 4-9" , then I was trying to do it similar to your approach but using the -o flag.
– user344036
2 days ago
1
@user344036 If Kusalananda's answer was helpful to you, it's courteous to mark the answer as "Accepted."
– Jim L.
yesterday
add a comment |
This sounds like a homework assignment, so I will give all the bits of the puzzle that you need to solve it.
- The number of arguments are kept in the special variable
$#
. - The third argument is
$3
. To see whether a variable
$var
is between 3 and 19 (inclusively), useif [ "$var" -ge 3 ] && [ "$var" -le 19 ]; then ...; fi
where
...
is the action you'd like to take if the statement is
true.Explicitly exiting from a script is done with
exit
. Explicitly returning from a function is done withreturn
. Both of these take an optional exit status.
This sounds like a homework assignment, so I will give all the bits of the puzzle that you need to solve it.
- The number of arguments are kept in the special variable
$#
. - The third argument is
$3
. To see whether a variable
$var
is between 3 and 19 (inclusively), useif [ "$var" -ge 3 ] && [ "$var" -le 19 ]; then ...; fi
where
...
is the action you'd like to take if the statement is
true.Explicitly exiting from a script is done with
exit
. Explicitly returning from a function is done withreturn
. Both of these take an optional exit status.
edited 2 days ago
answered 2 days ago
Kusalananda♦Kusalananda
138k17258428
138k17258428
Thank you so much it worked. I was having trouble wrapping my head around getting the range I was trying to do "$# -eq 4-9" , then I was trying to do it similar to your approach but using the -o flag.
– user344036
2 days ago
1
@user344036 If Kusalananda's answer was helpful to you, it's courteous to mark the answer as "Accepted."
– Jim L.
yesterday
add a comment |
Thank you so much it worked. I was having trouble wrapping my head around getting the range I was trying to do "$# -eq 4-9" , then I was trying to do it similar to your approach but using the -o flag.
– user344036
2 days ago
1
@user344036 If Kusalananda's answer was helpful to you, it's courteous to mark the answer as "Accepted."
– Jim L.
yesterday
Thank you so much it worked. I was having trouble wrapping my head around getting the range I was trying to do "$# -eq 4-9" , then I was trying to do it similar to your approach but using the -o flag.
– user344036
2 days ago
Thank you so much it worked. I was having trouble wrapping my head around getting the range I was trying to do "$# -eq 4-9" , then I was trying to do it similar to your approach but using the -o flag.
– user344036
2 days ago
1
1
@user344036 If Kusalananda's answer was helpful to you, it's courteous to mark the answer as "Accepted."
– Jim L.
yesterday
@user344036 If Kusalananda's answer was helpful to you, it's courteous to mark the answer as "Accepted."
– Jim L.
yesterday
add a comment |
user344036 is a new contributor. Be nice, and check out our Code of Conduct.
user344036 is a new contributor. Be nice, and check out our Code of Conduct.
user344036 is a new contributor. Be nice, and check out our Code of Conduct.
user344036 is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f509088%2fhow-do-i-start-an-if-function-in-shell-that-requires-the-user-to-input-between%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
3
Since this seems semi-arbitrary, have you learned anything about UNIX shells recently that would help you along this path? What have you tried and what were the results?
– Jeff Schaller♦
2 days ago
1
Some related reading: Positional Parameters, Conditional Constructs, Bash Builtin Commands, Bourne Builtin Commands
– Jesse_b
2 days ago