Counting program fails in arithmetic test
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
having a little trouble with this rather basic script. This script works on Bash in my macbook pro, but not on my Linux Mint desktop, which also uses bash.
I can't figure out what's wrong with it.
I'm still getting an error from bash saying:
line 6: [: -lt: unary operator expected
line 16: [: -gt: unary operator expected
with this updated code:
#!/bin/bash
clear
counter=0
function countup
while [ $counter -lt 500 ]
do
((counter++))
echo $counter
sleep 0.2
done
countdown
function countdown
while [ $counter -gt 0 ]
do
((counter--))
echo $counter
sleep 0.2
done
countup
countup
bash shell shell-script
add a comment |Â
up vote
0
down vote
favorite
having a little trouble with this rather basic script. This script works on Bash in my macbook pro, but not on my Linux Mint desktop, which also uses bash.
I can't figure out what's wrong with it.
I'm still getting an error from bash saying:
line 6: [: -lt: unary operator expected
line 16: [: -gt: unary operator expected
with this updated code:
#!/bin/bash
clear
counter=0
function countup
while [ $counter -lt 500 ]
do
((counter++))
echo $counter
sleep 0.2
done
countdown
function countdown
while [ $counter -gt 0 ]
do
((counter--))
echo $counter
sleep 0.2
done
countup
countup
bash shell shell-script
2
add space after0
=>0 ]
and remove:
in both functions
â Costas
Apr 11 '15 at 16:25
1
Take a look at: shellcheck.net
â Cyrus
Apr 11 '15 at 16:25
Shellcheck says it is all looking good, but I still get the error.
â CYQ00000A
Apr 11 '15 at 16:50
2
Works for me. Have you really posted the code you're running? Seems like $counter is empty in your real code (use"$counter"
).
â choroba
Apr 11 '15 at 16:53
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
having a little trouble with this rather basic script. This script works on Bash in my macbook pro, but not on my Linux Mint desktop, which also uses bash.
I can't figure out what's wrong with it.
I'm still getting an error from bash saying:
line 6: [: -lt: unary operator expected
line 16: [: -gt: unary operator expected
with this updated code:
#!/bin/bash
clear
counter=0
function countup
while [ $counter -lt 500 ]
do
((counter++))
echo $counter
sleep 0.2
done
countdown
function countdown
while [ $counter -gt 0 ]
do
((counter--))
echo $counter
sleep 0.2
done
countup
countup
bash shell shell-script
having a little trouble with this rather basic script. This script works on Bash in my macbook pro, but not on my Linux Mint desktop, which also uses bash.
I can't figure out what's wrong with it.
I'm still getting an error from bash saying:
line 6: [: -lt: unary operator expected
line 16: [: -gt: unary operator expected
with this updated code:
#!/bin/bash
clear
counter=0
function countup
while [ $counter -lt 500 ]
do
((counter++))
echo $counter
sleep 0.2
done
countdown
function countdown
while [ $counter -gt 0 ]
do
((counter--))
echo $counter
sleep 0.2
done
countup
countup
bash shell shell-script
bash shell shell-script
edited 32 mins ago
Rui F Ribeiro
37.3k1374118
37.3k1374118
asked Apr 11 '15 at 16:19
CYQ00000A
75
75
2
add space after0
=>0 ]
and remove:
in both functions
â Costas
Apr 11 '15 at 16:25
1
Take a look at: shellcheck.net
â Cyrus
Apr 11 '15 at 16:25
Shellcheck says it is all looking good, but I still get the error.
â CYQ00000A
Apr 11 '15 at 16:50
2
Works for me. Have you really posted the code you're running? Seems like $counter is empty in your real code (use"$counter"
).
â choroba
Apr 11 '15 at 16:53
add a comment |Â
2
add space after0
=>0 ]
and remove:
in both functions
â Costas
Apr 11 '15 at 16:25
1
Take a look at: shellcheck.net
â Cyrus
Apr 11 '15 at 16:25
Shellcheck says it is all looking good, but I still get the error.
â CYQ00000A
Apr 11 '15 at 16:50
2
Works for me. Have you really posted the code you're running? Seems like $counter is empty in your real code (use"$counter"
).
â choroba
Apr 11 '15 at 16:53
2
2
add space after
0
=> 0 ]
and remove :
in both functionsâ Costas
Apr 11 '15 at 16:25
add space after
0
=> 0 ]
and remove :
in both functionsâ Costas
Apr 11 '15 at 16:25
1
1
Take a look at: shellcheck.net
â Cyrus
Apr 11 '15 at 16:25
Take a look at: shellcheck.net
â Cyrus
Apr 11 '15 at 16:25
Shellcheck says it is all looking good, but I still get the error.
â CYQ00000A
Apr 11 '15 at 16:50
Shellcheck says it is all looking good, but I still get the error.
â CYQ00000A
Apr 11 '15 at 16:50
2
2
Works for me. Have you really posted the code you're running? Seems like $counter is empty in your real code (use
"$counter"
).â choroba
Apr 11 '15 at 16:53
Works for me. Have you really posted the code you're running? Seems like $counter is empty in your real code (use
"$counter"
).â choroba
Apr 11 '15 at 16:53
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
Try this:
#!/bin/bash
clear
counter=0
function countup
while [[ $counter -lt 500 ]]; do
((counter++))
echo $counter
sleep 0.2
done
countdown
function countdown
while [[ $counter -gt 0 ]]; do
((counter--))
echo $counter
sleep 0.2
done
countup
countup
[[ ]]
is a bit more robust to unvalued variables. But, this script does run. It seems that you typed it differently here than your machine. This also looks like it will count up and down forever, but that seems to be intentional.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Try this:
#!/bin/bash
clear
counter=0
function countup
while [[ $counter -lt 500 ]]; do
((counter++))
echo $counter
sleep 0.2
done
countdown
function countdown
while [[ $counter -gt 0 ]]; do
((counter--))
echo $counter
sleep 0.2
done
countup
countup
[[ ]]
is a bit more robust to unvalued variables. But, this script does run. It seems that you typed it differently here than your machine. This also looks like it will count up and down forever, but that seems to be intentional.
add a comment |Â
up vote
0
down vote
Try this:
#!/bin/bash
clear
counter=0
function countup
while [[ $counter -lt 500 ]]; do
((counter++))
echo $counter
sleep 0.2
done
countdown
function countdown
while [[ $counter -gt 0 ]]; do
((counter--))
echo $counter
sleep 0.2
done
countup
countup
[[ ]]
is a bit more robust to unvalued variables. But, this script does run. It seems that you typed it differently here than your machine. This also looks like it will count up and down forever, but that seems to be intentional.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Try this:
#!/bin/bash
clear
counter=0
function countup
while [[ $counter -lt 500 ]]; do
((counter++))
echo $counter
sleep 0.2
done
countdown
function countdown
while [[ $counter -gt 0 ]]; do
((counter--))
echo $counter
sleep 0.2
done
countup
countup
[[ ]]
is a bit more robust to unvalued variables. But, this script does run. It seems that you typed it differently here than your machine. This also looks like it will count up and down forever, but that seems to be intentional.
Try this:
#!/bin/bash
clear
counter=0
function countup
while [[ $counter -lt 500 ]]; do
((counter++))
echo $counter
sleep 0.2
done
countdown
function countdown
while [[ $counter -gt 0 ]]; do
((counter--))
echo $counter
sleep 0.2
done
countup
countup
[[ ]]
is a bit more robust to unvalued variables. But, this script does run. It seems that you typed it differently here than your machine. This also looks like it will count up and down forever, but that seems to be intentional.
answered Jun 25 '15 at 5:34
Will
1,451722
1,451722
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f195651%2fcounting-program-fails-in-arithmetic-test%23new-answer', 'question_page');
);
Post as a guest
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
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
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
2
add space after
0
=>0 ]
and remove:
in both functionsâ Costas
Apr 11 '15 at 16:25
1
Take a look at: shellcheck.net
â Cyrus
Apr 11 '15 at 16:25
Shellcheck says it is all looking good, but I still get the error.
â CYQ00000A
Apr 11 '15 at 16:50
2
Works for me. Have you really posted the code you're running? Seems like $counter is empty in your real code (use
"$counter"
).â choroba
Apr 11 '15 at 16:53