12

I feel like a idiot. But it won't work. Idk what I'm missing.

Comments
  • 0
    That's the output
  • 4
    Is there any point of all the "s ?

    Also you might wanna use -eq (i think, not sure) instead of =
  • 1
    have you send the output into base64 and debugged it manually?
  • 1
    Ehhh.
  • 2
    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
  • 0
    I tested the code somewhere else and it worked there.
  • 2
    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.
  • 0
    Stuck using shell since ubnt products don't support bash.
  • 0
    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.
  • 0
    Gimme a sec. I rewrite it for you.
  • 0
    ~ $ 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!

    ~ $
  • 0
    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.

    -.- ^^
  • 0
    It's possible that your var1 contains spaces. Try:

    echo "#$var1#"
  • 1
    @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.
  • 0
    @endor it's not Ubuntu. It's a ubiquiti radio.
  • 1
    Isn't it
    if [[ $var1 == $var2 ]]; then

    ?
  • 0
    @incognito Nah, that's bash, and thing doesn't want bash
  • 1
    @filthyranter how about just putting the grep inside the if?

    if [ $(mca-status) | grep lanSpeed=10Mbps-Full ]; then
  • 0
    sudo apt install shellcheck
    👌
  • 0
    Invective! Verb your adjective nouns!
  • 1
    * -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
  • 0
    @ohemelaar no apt install
  • 0
    @icycrash even in the remote?
  • 0
    @ohemelaar nothing. It is a wireless radio it runs a very stripped down custom version of Linux.
Add Comment