I'm not getting cube of the number
while [ "$c" = y -o "$c" = Y -o -z $c ]
do
echo enter a number;
read n;
if [ $n -ge 0 -a $n -le 50 ];then
echo "cube= `expr $n * $n * $n`";
fi;
echo y to continue or any to exit;
read c;
done
shell files
add a comment |
while [ "$c" = y -o "$c" = Y -o -z $c ]
do
echo enter a number;
read n;
if [ $n -ge 0 -a $n -le 50 ];then
echo "cube= `expr $n * $n * $n`";
fi;
echo y to continue or any to exit;
read c;
done
shell files
To ask a better question, you should describe (or better, show) what actually happens, and describe how that differs from what you want to happen.
– glenn jackman
Jan 11 at 21:02
add a comment |
while [ "$c" = y -o "$c" = Y -o -z $c ]
do
echo enter a number;
read n;
if [ $n -ge 0 -a $n -le 50 ];then
echo "cube= `expr $n * $n * $n`";
fi;
echo y to continue or any to exit;
read c;
done
shell files
while [ "$c" = y -o "$c" = Y -o -z $c ]
do
echo enter a number;
read n;
if [ $n -ge 0 -a $n -le 50 ];then
echo "cube= `expr $n * $n * $n`";
fi;
echo y to continue or any to exit;
read c;
done
shell files
shell files
edited Jan 11 at 19:52
fra-san
1,4051215
1,4051215
asked Jan 11 at 19:31
Parth PrajapatiParth Prajapati
111
111
To ask a better question, you should describe (or better, show) what actually happens, and describe how that differs from what you want to happen.
– glenn jackman
Jan 11 at 21:02
add a comment |
To ask a better question, you should describe (or better, show) what actually happens, and describe how that differs from what you want to happen.
– glenn jackman
Jan 11 at 21:02
To ask a better question, you should describe (or better, show) what actually happens, and describe how that differs from what you want to happen.
– glenn jackman
Jan 11 at 21:02
To ask a better question, you should describe (or better, show) what actually happens, and describe how that differs from what you want to happen.
– glenn jackman
Jan 11 at 21:02
add a comment |
2 Answers
2
active
oldest
votes
You've got a few problems with your shell script. First, you should quote $c
in the while (all of them — you missed the last one). Otherwise, when $c is empty (say, at the start of your program), the -z test gets passed nothing instead of the empty string, giving an error (something along the lines of "argument expected").
Second, you need to escape the *
in your expr
command. Otherwise it's trying to do a glob (match filenames), just like cat *
would do. Easiest is to escape it to *
. The error from that will depend on exactly what the * happens to expand to (i.e., which files are in your current directory), but will probably be something confusing!
That should at least get your script to run.
PS: There are a bunch more ways this could be improved, you might want to check out ShellCheck for some (automated) suggestions.
add a comment |
In bash, you could write:
PS3="Continue? "
while true; do
read -p "Enter a number: " n
((0 <= n && n <= 50)) && echo "cube = $((n * n * n))"
select ans in yes no; do
case $ans in
yes) break ;;
no) break 2 ;;
esac
done
done
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
});
}
});
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%2f494006%2fim-not-getting-cube-of-the-number%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You've got a few problems with your shell script. First, you should quote $c
in the while (all of them — you missed the last one). Otherwise, when $c is empty (say, at the start of your program), the -z test gets passed nothing instead of the empty string, giving an error (something along the lines of "argument expected").
Second, you need to escape the *
in your expr
command. Otherwise it's trying to do a glob (match filenames), just like cat *
would do. Easiest is to escape it to *
. The error from that will depend on exactly what the * happens to expand to (i.e., which files are in your current directory), but will probably be something confusing!
That should at least get your script to run.
PS: There are a bunch more ways this could be improved, you might want to check out ShellCheck for some (automated) suggestions.
add a comment |
You've got a few problems with your shell script. First, you should quote $c
in the while (all of them — you missed the last one). Otherwise, when $c is empty (say, at the start of your program), the -z test gets passed nothing instead of the empty string, giving an error (something along the lines of "argument expected").
Second, you need to escape the *
in your expr
command. Otherwise it's trying to do a glob (match filenames), just like cat *
would do. Easiest is to escape it to *
. The error from that will depend on exactly what the * happens to expand to (i.e., which files are in your current directory), but will probably be something confusing!
That should at least get your script to run.
PS: There are a bunch more ways this could be improved, you might want to check out ShellCheck for some (automated) suggestions.
add a comment |
You've got a few problems with your shell script. First, you should quote $c
in the while (all of them — you missed the last one). Otherwise, when $c is empty (say, at the start of your program), the -z test gets passed nothing instead of the empty string, giving an error (something along the lines of "argument expected").
Second, you need to escape the *
in your expr
command. Otherwise it's trying to do a glob (match filenames), just like cat *
would do. Easiest is to escape it to *
. The error from that will depend on exactly what the * happens to expand to (i.e., which files are in your current directory), but will probably be something confusing!
That should at least get your script to run.
PS: There are a bunch more ways this could be improved, you might want to check out ShellCheck for some (automated) suggestions.
You've got a few problems with your shell script. First, you should quote $c
in the while (all of them — you missed the last one). Otherwise, when $c is empty (say, at the start of your program), the -z test gets passed nothing instead of the empty string, giving an error (something along the lines of "argument expected").
Second, you need to escape the *
in your expr
command. Otherwise it's trying to do a glob (match filenames), just like cat *
would do. Easiest is to escape it to *
. The error from that will depend on exactly what the * happens to expand to (i.e., which files are in your current directory), but will probably be something confusing!
That should at least get your script to run.
PS: There are a bunch more ways this could be improved, you might want to check out ShellCheck for some (automated) suggestions.
answered Jan 11 at 19:43
derobertderobert
73k8154210
73k8154210
add a comment |
add a comment |
In bash, you could write:
PS3="Continue? "
while true; do
read -p "Enter a number: " n
((0 <= n && n <= 50)) && echo "cube = $((n * n * n))"
select ans in yes no; do
case $ans in
yes) break ;;
no) break 2 ;;
esac
done
done
add a comment |
In bash, you could write:
PS3="Continue? "
while true; do
read -p "Enter a number: " n
((0 <= n && n <= 50)) && echo "cube = $((n * n * n))"
select ans in yes no; do
case $ans in
yes) break ;;
no) break 2 ;;
esac
done
done
add a comment |
In bash, you could write:
PS3="Continue? "
while true; do
read -p "Enter a number: " n
((0 <= n && n <= 50)) && echo "cube = $((n * n * n))"
select ans in yes no; do
case $ans in
yes) break ;;
no) break 2 ;;
esac
done
done
In bash, you could write:
PS3="Continue? "
while true; do
read -p "Enter a number: " n
((0 <= n && n <= 50)) && echo "cube = $((n * n * n))"
select ans in yes no; do
case $ans in
yes) break ;;
no) break 2 ;;
esac
done
done
answered Jan 11 at 21:01
glenn jackmanglenn jackman
51.1k571110
51.1k571110
add a comment |
add a comment |
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%2f494006%2fim-not-getting-cube-of-the-number%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
To ask a better question, you should describe (or better, show) what actually happens, and describe how that differs from what you want to happen.
– glenn jackman
Jan 11 at 21:02