shell script to check if input is a string/integer/floatBash script, cannote replace string in a file with escaped $ and &Evaluating a string in shell scriptCan you help me to understand this explanation of shell quoting?Shell script file (.sh) does not run, and throws an errorBash always evaluate Regex as trueexit code of diffreplace a string by variable in a file using bash scriptAutomated Shell script to run fdisk command with user inputCreate bash script that allows you to choose multiple options instead of just one?How to check if a package is installed from Bash?
What explanation do proponents of a Scotland-NI bridge give for it breaking Brexit impasse?
Parallel resistance in electric circuits
What organs or modifications would be needed for a life biological creature not to require sleep?
Insight into cavity resonators
How much would a 1 foot tall human weigh?
Why is this sentence grammatical?
Are there any rules about taking damage whilst holding your breath in combat?
International Orange?
geschafft or geschaffen? which one is past participle of schaffen?
What would happen if Protagoras v Euathlus were heard in court today?
Asked to Not Use Transactions and to Use A Workaround to Simulate One
Why is the UK still pressing on with Brexit?
Unable to find solution to 6 simultaneous equations
Is there any way to land a rover on the Moon without using any thrusters?
Some Prime Peerage
Should you only use colons and periods in dialogues?
If I want an interpretable model, are there methods other than Linear Regression?
In what state are satellites left in when they are left in a graveyard orbit?
How to control the output voltage of a solid state relay
In what sequence should an advanced civilization teach technology to medieval society to maximize rate of adoption?
Ethernet, Wifi and a little human psychology
How would you control supersoldiers in a late iron-age society?
Shouldn't countries like Russia and Canada support global warming?
Bash awk command with quotes
shell script to check if input is a string/integer/float
Bash script, cannote replace string in a file with escaped $ and &Evaluating a string in shell scriptCan you help me to understand this explanation of shell quoting?Shell script file (.sh) does not run, and throws an errorBash always evaluate Regex as trueexit code of diffreplace a string by variable in a file using bash scriptAutomated Shell script to run fdisk command with user inputCreate bash script that allows you to choose multiple options instead of just one?How to check if a package is installed from Bash?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
#!/bin/bash
read -p "Enter value:" val
echo "$val"|grep "^[0-9]*$"
val="$?"
if [[ $val == 0 ]]
then
echo "Integer"
exit
fi
echo $val|grep "^[a-zA-Z]*$"
val="$?"
if [[ $val == 0 ]]
then
echo "String"
exit
fi
echo $val|grep "^[0-9]*.[0-9]*$"
val="$?"
if [[ $val == 0 ]]
then
echo "Float"
exit
fi
If I enter a string like "ape" it says "grep invalid range" and then prints float. Where did I go wrong?
bash scripts
add a comment
|
#!/bin/bash
read -p "Enter value:" val
echo "$val"|grep "^[0-9]*$"
val="$?"
if [[ $val == 0 ]]
then
echo "Integer"
exit
fi
echo $val|grep "^[a-zA-Z]*$"
val="$?"
if [[ $val == 0 ]]
then
echo "String"
exit
fi
echo $val|grep "^[0-9]*.[0-9]*$"
val="$?"
if [[ $val == 0 ]]
then
echo "Float"
exit
fi
If I enter a string like "ape" it says "grep invalid range" and then prints float. Where did I go wrong?
bash scripts
1
What locale are you using? Please edit your question and include the output oflocale.
– terdon♦
8 hours ago
1
+1 - you should probably also rethink re-using the same variable name (val) for the exit status that you use for the value to be tested. Also==is a lexical test (to test an integer exit status better to use-eq). And remember that.means "any character" in a grep regular expression - if you want a literal decimal point, use.
– steeldriver
8 hours ago
add a comment
|
#!/bin/bash
read -p "Enter value:" val
echo "$val"|grep "^[0-9]*$"
val="$?"
if [[ $val == 0 ]]
then
echo "Integer"
exit
fi
echo $val|grep "^[a-zA-Z]*$"
val="$?"
if [[ $val == 0 ]]
then
echo "String"
exit
fi
echo $val|grep "^[0-9]*.[0-9]*$"
val="$?"
if [[ $val == 0 ]]
then
echo "Float"
exit
fi
If I enter a string like "ape" it says "grep invalid range" and then prints float. Where did I go wrong?
bash scripts
#!/bin/bash
read -p "Enter value:" val
echo "$val"|grep "^[0-9]*$"
val="$?"
if [[ $val == 0 ]]
then
echo "Integer"
exit
fi
echo $val|grep "^[a-zA-Z]*$"
val="$?"
if [[ $val == 0 ]]
then
echo "String"
exit
fi
echo $val|grep "^[0-9]*.[0-9]*$"
val="$?"
if [[ $val == 0 ]]
then
echo "Float"
exit
fi
If I enter a string like "ape" it says "grep invalid range" and then prints float. Where did I go wrong?
bash scripts
bash scripts
asked 8 hours ago
miamia
133 bronze badges
133 bronze badges
1
What locale are you using? Please edit your question and include the output oflocale.
– terdon♦
8 hours ago
1
+1 - you should probably also rethink re-using the same variable name (val) for the exit status that you use for the value to be tested. Also==is a lexical test (to test an integer exit status better to use-eq). And remember that.means "any character" in a grep regular expression - if you want a literal decimal point, use.
– steeldriver
8 hours ago
add a comment
|
1
What locale are you using? Please edit your question and include the output oflocale.
– terdon♦
8 hours ago
1
+1 - you should probably also rethink re-using the same variable name (val) for the exit status that you use for the value to be tested. Also==is a lexical test (to test an integer exit status better to use-eq). And remember that.means "any character" in a grep regular expression - if you want a literal decimal point, use.
– steeldriver
8 hours ago
1
1
What locale are you using? Please edit your question and include the output of
locale.– terdon♦
8 hours ago
What locale are you using? Please edit your question and include the output of
locale.– terdon♦
8 hours ago
1
1
+1 - you should probably also rethink re-using the same variable name (
val) for the exit status that you use for the value to be tested. Also == is a lexical test (to test an integer exit status better to use -eq ). And remember that . means "any character" in a grep regular expression - if you want a literal decimal point, use .– steeldriver
8 hours ago
+1 - you should probably also rethink re-using the same variable name (
val) for the exit status that you use for the value to be tested. Also == is a lexical test (to test an integer exit status better to use -eq ). And remember that . means "any character" in a grep regular expression - if you want a literal decimal point, use .– steeldriver
8 hours ago
add a comment
|
2 Answers
2
active
oldest
votes
This bash code returns integer for integers like 123, float for floating point numbers like 123.4 and string for any other input values like "123", One23 123. or 123.4.5.
#!/bin/bash
read -p "Type a number or a string: " input
if [[ $input =~ ^[+-]?[0-9]+$ ]]; then
echo "Input is an integer."
elif [[ $input =~ ^[+-]?[0-9]+.$ ]]; then
echo "Input is a string."
elif [[ $input =~ ^[+-]?[0-9]+.?[0-9]*$ ]]; then
echo "Input is a float."
else
echo "Input is a string."
fi
"00001" is a string not an integer :+
– Rinzwind
7 hours ago
This will also consider+or-(alone) as integers. Same for an empty string. And it will report1.as a float.
– terdon♦
7 hours ago
I fixed the+and-problem, but it still chokes on1..
– terdon♦
7 hours ago
I edited it so it doesn't choke on 1. anymore.
– karel
6 hours ago
Leading zeroes => octal.$ echo $(( 0009 * 2 ))->bash: 0009: value too great for base (error token is "0009")
– Hannu
6 hours ago
add a comment
|
I can't reproduce your error, but since it's complaining about an invalid range, it's most likely a locale issue. Try running your script again, but setting the locale:
LC_ALL=C yourscript.sh
Of course, that won't fix the other problem which is:
echo $val|grep "^[a-zA-Z]*$"
val="$?"
After those lines, $val is no longer the value you gave, it is now the exit status of the grep, so everything after that is testing the wrong thing.
In any case, this is really needlessly complex. All you really need is:
#!/bin/bash
val="$@"
[[ -z $val ]] && echo "No input!" && exit
if [[ "$val" =~ ^[+-]?[0-9]+$ ]]; then
echo "Number!"
elif [[ $val =~ ^[+-]?[0-9]*.[0-9]+$ ]]; then
echo "Float!"
elif [[ $val =~ [0-9] ]]; then
echo "Mixed, some numbers"
else
echo "No numbers!"
fi
Note that I'm using val="$@" instead of read. This means you can now run your script as yourscript.sh input instead of having to type out the input every time. That way, you can see what you did in the history, you avoid typing errors, you can run the script automatically etc. It is generally a bad idea to use read and force your users to enter input.
Also note that I changed some of your terms. I now consider 4 possibilities:
- The input has nothing but numbers: print "Number" (whether
001002is an integer depends on what sort of maths you're thinking of). - The input consists of 0 or more numbers, then a dot and then nothing but numbers (0 or more because
.2can be considered valid in some cases; if you don't want that, change the^d*.d+$to^d+.d+$). - The input has numbers but not only numbers: print "Mixed, some numbers". Note that this will also catch
1.which is not a valid float and not a valid integer. - The input has no numbers: print "No numbers".
I split 3 and 4, but you can join them and have them print the same, if you like.
Also, kudos to Karel for thinking of +N and -N numbers.
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/4.0/"u003ecc by-sa 4.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%2f1174142%2fshell-script-to-check-if-input-is-a-string-integer-float%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
This bash code returns integer for integers like 123, float for floating point numbers like 123.4 and string for any other input values like "123", One23 123. or 123.4.5.
#!/bin/bash
read -p "Type a number or a string: " input
if [[ $input =~ ^[+-]?[0-9]+$ ]]; then
echo "Input is an integer."
elif [[ $input =~ ^[+-]?[0-9]+.$ ]]; then
echo "Input is a string."
elif [[ $input =~ ^[+-]?[0-9]+.?[0-9]*$ ]]; then
echo "Input is a float."
else
echo "Input is a string."
fi
"00001" is a string not an integer :+
– Rinzwind
7 hours ago
This will also consider+or-(alone) as integers. Same for an empty string. And it will report1.as a float.
– terdon♦
7 hours ago
I fixed the+and-problem, but it still chokes on1..
– terdon♦
7 hours ago
I edited it so it doesn't choke on 1. anymore.
– karel
6 hours ago
Leading zeroes => octal.$ echo $(( 0009 * 2 ))->bash: 0009: value too great for base (error token is "0009")
– Hannu
6 hours ago
add a comment
|
This bash code returns integer for integers like 123, float for floating point numbers like 123.4 and string for any other input values like "123", One23 123. or 123.4.5.
#!/bin/bash
read -p "Type a number or a string: " input
if [[ $input =~ ^[+-]?[0-9]+$ ]]; then
echo "Input is an integer."
elif [[ $input =~ ^[+-]?[0-9]+.$ ]]; then
echo "Input is a string."
elif [[ $input =~ ^[+-]?[0-9]+.?[0-9]*$ ]]; then
echo "Input is a float."
else
echo "Input is a string."
fi
"00001" is a string not an integer :+
– Rinzwind
7 hours ago
This will also consider+or-(alone) as integers. Same for an empty string. And it will report1.as a float.
– terdon♦
7 hours ago
I fixed the+and-problem, but it still chokes on1..
– terdon♦
7 hours ago
I edited it so it doesn't choke on 1. anymore.
– karel
6 hours ago
Leading zeroes => octal.$ echo $(( 0009 * 2 ))->bash: 0009: value too great for base (error token is "0009")
– Hannu
6 hours ago
add a comment
|
This bash code returns integer for integers like 123, float for floating point numbers like 123.4 and string for any other input values like "123", One23 123. or 123.4.5.
#!/bin/bash
read -p "Type a number or a string: " input
if [[ $input =~ ^[+-]?[0-9]+$ ]]; then
echo "Input is an integer."
elif [[ $input =~ ^[+-]?[0-9]+.$ ]]; then
echo "Input is a string."
elif [[ $input =~ ^[+-]?[0-9]+.?[0-9]*$ ]]; then
echo "Input is a float."
else
echo "Input is a string."
fi
This bash code returns integer for integers like 123, float for floating point numbers like 123.4 and string for any other input values like "123", One23 123. or 123.4.5.
#!/bin/bash
read -p "Type a number or a string: " input
if [[ $input =~ ^[+-]?[0-9]+$ ]]; then
echo "Input is an integer."
elif [[ $input =~ ^[+-]?[0-9]+.$ ]]; then
echo "Input is a string."
elif [[ $input =~ ^[+-]?[0-9]+.?[0-9]*$ ]]; then
echo "Input is a float."
else
echo "Input is a string."
fi
edited 6 hours ago
answered 7 hours ago
karelkarel
67.9k14 gold badges152 silver badges172 bronze badges
67.9k14 gold badges152 silver badges172 bronze badges
"00001" is a string not an integer :+
– Rinzwind
7 hours ago
This will also consider+or-(alone) as integers. Same for an empty string. And it will report1.as a float.
– terdon♦
7 hours ago
I fixed the+and-problem, but it still chokes on1..
– terdon♦
7 hours ago
I edited it so it doesn't choke on 1. anymore.
– karel
6 hours ago
Leading zeroes => octal.$ echo $(( 0009 * 2 ))->bash: 0009: value too great for base (error token is "0009")
– Hannu
6 hours ago
add a comment
|
"00001" is a string not an integer :+
– Rinzwind
7 hours ago
This will also consider+or-(alone) as integers. Same for an empty string. And it will report1.as a float.
– terdon♦
7 hours ago
I fixed the+and-problem, but it still chokes on1..
– terdon♦
7 hours ago
I edited it so it doesn't choke on 1. anymore.
– karel
6 hours ago
Leading zeroes => octal.$ echo $(( 0009 * 2 ))->bash: 0009: value too great for base (error token is "0009")
– Hannu
6 hours ago
"00001" is a string not an integer :+
– Rinzwind
7 hours ago
"00001" is a string not an integer :+
– Rinzwind
7 hours ago
This will also consider
+ or - (alone) as integers. Same for an empty string. And it will report 1. as a float.– terdon♦
7 hours ago
This will also consider
+ or - (alone) as integers. Same for an empty string. And it will report 1. as a float.– terdon♦
7 hours ago
I fixed the
+ and - problem, but it still chokes on 1..– terdon♦
7 hours ago
I fixed the
+ and - problem, but it still chokes on 1..– terdon♦
7 hours ago
I edited it so it doesn't choke on 1. anymore.
– karel
6 hours ago
I edited it so it doesn't choke on 1. anymore.
– karel
6 hours ago
Leading zeroes => octal.
$ echo $(( 0009 * 2 )) -> bash: 0009: value too great for base (error token is "0009")– Hannu
6 hours ago
Leading zeroes => octal.
$ echo $(( 0009 * 2 )) -> bash: 0009: value too great for base (error token is "0009")– Hannu
6 hours ago
add a comment
|
I can't reproduce your error, but since it's complaining about an invalid range, it's most likely a locale issue. Try running your script again, but setting the locale:
LC_ALL=C yourscript.sh
Of course, that won't fix the other problem which is:
echo $val|grep "^[a-zA-Z]*$"
val="$?"
After those lines, $val is no longer the value you gave, it is now the exit status of the grep, so everything after that is testing the wrong thing.
In any case, this is really needlessly complex. All you really need is:
#!/bin/bash
val="$@"
[[ -z $val ]] && echo "No input!" && exit
if [[ "$val" =~ ^[+-]?[0-9]+$ ]]; then
echo "Number!"
elif [[ $val =~ ^[+-]?[0-9]*.[0-9]+$ ]]; then
echo "Float!"
elif [[ $val =~ [0-9] ]]; then
echo "Mixed, some numbers"
else
echo "No numbers!"
fi
Note that I'm using val="$@" instead of read. This means you can now run your script as yourscript.sh input instead of having to type out the input every time. That way, you can see what you did in the history, you avoid typing errors, you can run the script automatically etc. It is generally a bad idea to use read and force your users to enter input.
Also note that I changed some of your terms. I now consider 4 possibilities:
- The input has nothing but numbers: print "Number" (whether
001002is an integer depends on what sort of maths you're thinking of). - The input consists of 0 or more numbers, then a dot and then nothing but numbers (0 or more because
.2can be considered valid in some cases; if you don't want that, change the^d*.d+$to^d+.d+$). - The input has numbers but not only numbers: print "Mixed, some numbers". Note that this will also catch
1.which is not a valid float and not a valid integer. - The input has no numbers: print "No numbers".
I split 3 and 4, but you can join them and have them print the same, if you like.
Also, kudos to Karel for thinking of +N and -N numbers.
add a comment
|
I can't reproduce your error, but since it's complaining about an invalid range, it's most likely a locale issue. Try running your script again, but setting the locale:
LC_ALL=C yourscript.sh
Of course, that won't fix the other problem which is:
echo $val|grep "^[a-zA-Z]*$"
val="$?"
After those lines, $val is no longer the value you gave, it is now the exit status of the grep, so everything after that is testing the wrong thing.
In any case, this is really needlessly complex. All you really need is:
#!/bin/bash
val="$@"
[[ -z $val ]] && echo "No input!" && exit
if [[ "$val" =~ ^[+-]?[0-9]+$ ]]; then
echo "Number!"
elif [[ $val =~ ^[+-]?[0-9]*.[0-9]+$ ]]; then
echo "Float!"
elif [[ $val =~ [0-9] ]]; then
echo "Mixed, some numbers"
else
echo "No numbers!"
fi
Note that I'm using val="$@" instead of read. This means you can now run your script as yourscript.sh input instead of having to type out the input every time. That way, you can see what you did in the history, you avoid typing errors, you can run the script automatically etc. It is generally a bad idea to use read and force your users to enter input.
Also note that I changed some of your terms. I now consider 4 possibilities:
- The input has nothing but numbers: print "Number" (whether
001002is an integer depends on what sort of maths you're thinking of). - The input consists of 0 or more numbers, then a dot and then nothing but numbers (0 or more because
.2can be considered valid in some cases; if you don't want that, change the^d*.d+$to^d+.d+$). - The input has numbers but not only numbers: print "Mixed, some numbers". Note that this will also catch
1.which is not a valid float and not a valid integer. - The input has no numbers: print "No numbers".
I split 3 and 4, but you can join them and have them print the same, if you like.
Also, kudos to Karel for thinking of +N and -N numbers.
add a comment
|
I can't reproduce your error, but since it's complaining about an invalid range, it's most likely a locale issue. Try running your script again, but setting the locale:
LC_ALL=C yourscript.sh
Of course, that won't fix the other problem which is:
echo $val|grep "^[a-zA-Z]*$"
val="$?"
After those lines, $val is no longer the value you gave, it is now the exit status of the grep, so everything after that is testing the wrong thing.
In any case, this is really needlessly complex. All you really need is:
#!/bin/bash
val="$@"
[[ -z $val ]] && echo "No input!" && exit
if [[ "$val" =~ ^[+-]?[0-9]+$ ]]; then
echo "Number!"
elif [[ $val =~ ^[+-]?[0-9]*.[0-9]+$ ]]; then
echo "Float!"
elif [[ $val =~ [0-9] ]]; then
echo "Mixed, some numbers"
else
echo "No numbers!"
fi
Note that I'm using val="$@" instead of read. This means you can now run your script as yourscript.sh input instead of having to type out the input every time. That way, you can see what you did in the history, you avoid typing errors, you can run the script automatically etc. It is generally a bad idea to use read and force your users to enter input.
Also note that I changed some of your terms. I now consider 4 possibilities:
- The input has nothing but numbers: print "Number" (whether
001002is an integer depends on what sort of maths you're thinking of). - The input consists of 0 or more numbers, then a dot and then nothing but numbers (0 or more because
.2can be considered valid in some cases; if you don't want that, change the^d*.d+$to^d+.d+$). - The input has numbers but not only numbers: print "Mixed, some numbers". Note that this will also catch
1.which is not a valid float and not a valid integer. - The input has no numbers: print "No numbers".
I split 3 and 4, but you can join them and have them print the same, if you like.
Also, kudos to Karel for thinking of +N and -N numbers.
I can't reproduce your error, but since it's complaining about an invalid range, it's most likely a locale issue. Try running your script again, but setting the locale:
LC_ALL=C yourscript.sh
Of course, that won't fix the other problem which is:
echo $val|grep "^[a-zA-Z]*$"
val="$?"
After those lines, $val is no longer the value you gave, it is now the exit status of the grep, so everything after that is testing the wrong thing.
In any case, this is really needlessly complex. All you really need is:
#!/bin/bash
val="$@"
[[ -z $val ]] && echo "No input!" && exit
if [[ "$val" =~ ^[+-]?[0-9]+$ ]]; then
echo "Number!"
elif [[ $val =~ ^[+-]?[0-9]*.[0-9]+$ ]]; then
echo "Float!"
elif [[ $val =~ [0-9] ]]; then
echo "Mixed, some numbers"
else
echo "No numbers!"
fi
Note that I'm using val="$@" instead of read. This means you can now run your script as yourscript.sh input instead of having to type out the input every time. That way, you can see what you did in the history, you avoid typing errors, you can run the script automatically etc. It is generally a bad idea to use read and force your users to enter input.
Also note that I changed some of your terms. I now consider 4 possibilities:
- The input has nothing but numbers: print "Number" (whether
001002is an integer depends on what sort of maths you're thinking of). - The input consists of 0 or more numbers, then a dot and then nothing but numbers (0 or more because
.2can be considered valid in some cases; if you don't want that, change the^d*.d+$to^d+.d+$). - The input has numbers but not only numbers: print "Mixed, some numbers". Note that this will also catch
1.which is not a valid float and not a valid integer. - The input has no numbers: print "No numbers".
I split 3 and 4, but you can join them and have them print the same, if you like.
Also, kudos to Karel for thinking of +N and -N numbers.
edited 7 hours ago
answered 7 hours ago
terdon♦terdon
74k14 gold badges151 silver badges235 bronze badges
74k14 gold badges151 silver badges235 bronze badges
add a comment
|
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%2f1174142%2fshell-script-to-check-if-input-is-a-string-integer-float%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
1
What locale are you using? Please edit your question and include the output of
locale.– terdon♦
8 hours ago
1
+1 - you should probably also rethink re-using the same variable name (
val) for the exit status that you use for the value to be tested. Also==is a lexical test (to test an integer exit status better to use-eq). And remember that.means "any character" in a grep regular expression - if you want a literal decimal point, use.– steeldriver
8 hours ago