Never mind I seem to have solved it. o.o;
I guess I edited the script so much that when I had -q on grep I edited something else that screwed up the script now that I typed everything again it works. Sorry if I wasted anyone's time just glad I finally got it working.
Okay I have this line in a script:
-8, 8, hat, 2i Would produce "not"
-.8, .8 Would produce "floating" which would be the appropriate thing to do.
I then tried modifying it:
Which I've then tried in other scripts that have similar lines as well as other methods and they all work fine on everything except for this one line.
Actually wait right I now get it..no wait I don't I was going to say it shows the whole line which I think I did have a problem earlier which was fixed with adding the -q option to grep.
Now I've realized a8 and ,8 show up as well but when I for example grep for "random string" in a file it does show the whole line but only highlights the random string not the whole line. This seems to think the whole line is the string even though only what I'm looking for should be the string no ?
-8 produces "floating" when I want "not" to appear.
-.8, .8 produce "float"
hat, 2i produce "not"
I've tried quoting "$REPLY" as people have said it's required nothing changes. Made sure the regex isn't quoted as people have said it'll be treated as a literal.
Oh wait 322 also gives me the wrong output. Am I just not getting how regex works ?
I thought
At beginning///minus///0-1///number///0+///escape character///dot///number///1+///end
Did I get that wrong ?
I'm going to take a guess and say that neither a pipe/grep can be used in a script/test ?
It's just so weird that it's worked plenty of times before. Why it took so long for this to happen if you can't pipe or grep in a test although I've tried variables and other methods and nothing seems to be working.
If anyone could point me in the right direction I'd really appreciate it.
And if something is unclear (it always seems to be ^^; ) please let me know so that I can try to clarify it.
Edit:
Forgot I tried:
echo "number" | grep -E ^-?[[:digit:]]\.[[:digit:]]+$
322 and -8 are shown as well as .8 and -.8
But not 8
And out of the script if something was messing it up I would think this would have it work so it's really confusing me...
I guess I edited the script so much that when I had -q on grep I edited something else that screwed up the script now that I typed everything again it works. Sorry if I wasted anyone's time just glad I finally got it working.
Code:
if [[ $REPLY =~ ^-?[[:digit:]]*\.[[:digit:]]+$ ]]; then
echo "floating"
else
echo "not"
fi
-.8, .8 Would produce "floating" which would be the appropriate thing to do.
I then tried modifying it:
Code:
[ $(echo $REPLY | grep -E ^-?[[:digit:]]*\.[[:digit:]]+$) ]
Actually wait right I now get it..no wait I don't I was going to say it shows the whole line which I think I did have a problem earlier which was fixed with adding the -q option to grep.
Now I've realized a8 and ,8 show up as well but when I for example grep for "random string" in a file it does show the whole line but only highlights the random string not the whole line. This seems to think the whole line is the string even though only what I'm looking for should be the string no ?
-8 produces "floating" when I want "not" to appear.
-.8, .8 produce "float"
hat, 2i produce "not"
I've tried quoting "$REPLY" as people have said it's required nothing changes. Made sure the regex isn't quoted as people have said it'll be treated as a literal.
Oh wait 322 also gives me the wrong output. Am I just not getting how regex works ?
I thought
At beginning///minus///0-1///number///0+///escape character///dot///number///1+///end
Did I get that wrong ?
I'm going to take a guess and say that neither a pipe/grep can be used in a script/test ?
It's just so weird that it's worked plenty of times before. Why it took so long for this to happen if you can't pipe or grep in a test although I've tried variables and other methods and nothing seems to be working.
If anyone could point me in the right direction I'd really appreciate it.
And if something is unclear (it always seems to be ^^; ) please let me know so that I can try to clarify it.
Edit:
Forgot I tried:
echo "number" | grep -E ^-?[[:digit:]]\.[[:digit:]]+$
322 and -8 are shown as well as .8 and -.8
But not 8
And out of the script if something was messing it up I would think this would have it work so it's really confusing me...