uboot if; then; else

Gast #3895069
Lesenswert?
• ▲
▼
hi,

ich würde gerne im uboot eine lokale variable setzen und diese in einer 
if-then-else abfragen ... jedoch ist da irgend etwas komisch ...

- variable "nea" auf 0 setzen
- ein script "x" erstellen und ausführen .... OK
- variable "nea" auf 1 setzen
- script "x" ausführen ... NOK?!

... ich verstehs nicht ... was mach ich falsch?

1
U-Boot# nea=0
2
U-Boot# setenv x "if itest 1 -eq $nea; then echo var1; else echo var0; fi;"
3
U-Boot# run x
4
var0
5
U-Boot# nea=1
6
U-Boot# run x
7
var0
8
U-Boot# echo $nea
9
1



thx,
Neubi   ... PS: die variable sollte nicht gespeichert werden (saveenv)
Gast #3896141
Lesenswert?
• ▲
▼
... danke Wolgang!


Dear Andreas,

In message <5470D48C.1080103@gmx.at> you wrote:
>
> i'm trying to set a local variable and test the variable in an
> if-then-else script ...
> but it's somehow a bit weird!?

Not really weird; you just have to be a bit careful about quoting
rules...

> - set variable "nea" to 0
> - create a script "x" and run .... OK
> - modify variable "nea" to 1
> - run script "x" again ... NOK?!
>
> ... what i'm doing wrong  -  the behavior is the same with 2013.10 and
> 2014.01

...and it would be the same if you were testing with a regular shell on
the Linux command line.

Actually this is something I always recommend: if you see some strange
behaviour, first try to do the same in a standard shell environment,
and debug it there.


>  >U-Boot# nea=0
>  >U-Boot# setenv x "if itest 1 -eq $nea; then echo var1; else echo var0;
> fi;"

It would have been a good idea here todo a "printenv x" to check what
was actually stored in the variable - this would have shown your
problem.  The thing is, you want to keep the '$nea' notation in the
variable, so you can evaluate the variable when you run that macro.
However, inside double quotes (") variable substitution takes place,
so above command is equivalent to

    setenv x "if itest 1 -eq 0; then echo var1; else echo var0; fi;"

>  >U-Boot# run x
>  >var0
>  >U-Boot# nea=1
>  >U-Boot# run x
>  >var0            <<<<<----- so now i should get the "var1" as a result
>  >U-Boot# echo $nea
>  >1

Use printenv to verify what is stored in the variable x, and you will
understand this.


Best regards,
Wolfgang Denk

Antwort schreiben

Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt. Bitte hier nur auf die ursprüngliche Frage antworten, für neue Fragen einen neuen Beitrag erstellen.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.