Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Is there any point of all the "s ?
Also you might wanna use -eq (i think, not sure) instead of = -
https://tldp.org/LDP/abs/...
First I would add the she bang - do you want Shell or Bash?
What you are doing is nearly correct I think - just drop the quotes around the command (Edit: var1 assignment)
echo output leads you in a dead end.
If I'm right, the first var that captures contains quotes (Edit: var1 assignment)
Echo drops the quotes.
That's what the previous poster with the base64 solution wanted to suggest: encode the string inside the variable so it cannot contain stuff that could be interpreted
Alternatives would be eg hashing -
Somewhere else....
As the she bang is missing calling ./ will call the system shell.
Check If they're the same in both machines and the version is the same.
That's the reason the shebang should be there:
#/bin/bash
#/bin/sh
First one is mostly what u want.
Shell compatibility is hell.
And I mean hell. Endless torture. -
Output from my trusty Router:
root@DD-WRT:~# ls -l /bin/bash
ls -l /bin/bash
lrwxrwxrwx 1 root root 13 Dec 27 13:01 /bin/bash -> /opt/bin/bash
#/bin/bash would use /opt/bin/bash
If it doesn't exist fails hard.
root@DD-WRT:~# ls -l /bin/sh
ls -l /bin/sh
lrwxrwxrwx 1 root root 7 Dec 27 13:00 /bin/sh -> busybox
/bin/sh is default interpreter...
So ./ or #/bin/sh would use this.
root@DD-WRT:~# sh -v
sh -v
BusyBox v.... built-in shell (ash)
Ash is in this case used.
Interesting readup:
https://en.m.wikipedia.org/wiki/...
"POSIX compliance
During the transition by Ubuntu, numerous scripts making use of bash-specific functionality (but not declaring it) were discovered.[10][11] The elements understood only by bash were called bashisms.
...."
I don't want to annoy you - but Not using a shebang and assuring you are using the same interpreter can make u go insane.
As compatibility can mean anything from: I don't care to I fail. -
~ $ cat ~/apps/bin/mca-status
#!/bin/bash
printf "bla=bla\n";
printf "lanSpeed=10Mbps-Full\n";
printf "xy=xz\n";
~ $ ~/apps/bin/mca-status | grep 'lanSpeed'
lanSpeed=10Mbps-Full
~ $ cat ~/test.sh
#!/bin/bb
VAR1=`mca-status | grep 'lanSpeed'`
VAR2='lanSpeed=10Mbps-Full'
if [ x"$VAR1" == x"$VAR2" ]; then
echo 'Matched!'
else
echo 'Did not match.'
fi;
exit 0;
~ $ ~/test.sh
Matched!
~ $ -
I've tried to make it as understandable as possible.
You should change the shebang - in my case it is /bin/bb so it uses busybox shell mode (ash).
The assignment uses `...` which should be compatible in all cases.
The x"..." comparison is very old - working around possible mischief with empty strings (we shouldn't have those, but god knows...).
Otherwise I've just used echo instead of reboot, don't like my machine rebooting for nothing ;)
exit 0 at the ende makes sure the shell terminates with an explicit return code - some shells don't like it implicitly.
Edit: Little typo: It should be a single equal sign in the if statement. blarg.
-.- ^^ -
endor56706y@icycrash in your first pic you wrote:
if [ a = b ];
ie assignment, instead of == ie check for equality.
In your last pic, you removed a semicolon after the if [...] block, and also your strings were *not* matching, since your grep output had '100Mbps', while you were checking for '10Mbps', so there was an extra zero.
Also, how on earth does #!/bin/bash not work on ubuntu? It's basically the only shell I've ever used and relied on, and it's always been there, both on ubuntu desktop and on ubuntu server. -
@filthyranter how about just putting the grep inside the if?
if [ $(mca-status) | grep lanSpeed=10Mbps-Full ]; then -
stacked26716y* -eq is for comparing numbers
* = is the correct way to check for string equality, == is not supported by [ ... ] (aka test)
* [[ ... ]] is not available in the POSIX shell -
icycrash6836y@ohemelaar nothing. It is a wireless radio it runs a very stripped down custom version of Linux.
I feel like a idiot. But it won't work. Idk what I'm missing.
rant