Skip to contentSkip to conversation

Add expr command

PATCH Superseded Kumar Gala 4 participants 5 messages Feb 13, 2008

lore
Share & tools
lore

Kumar Gala

author
#0 lore raw

PATCH v2 1/1 Add expr command

Add a simple expr command that will set an env variable as the result of the command. This allows us to do simple math in shell. The following operations are supported: &, |, ^, +, -, *, /.

---

Added xor (^) and check that the op arg is only one char as suggsted by Andreas.

- k

 common/Makefile   |    1 +
 common/cmd_expr.c |   70 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 0 deletions(-)
 create mode 100644 common/cmd_expr.c
common/Makefile +1 -0
index 1639109..4f3e711 100644
@@ -54,6 +54,7 @@ COBJS-$(CONFIG_CMD_DOC) += cmd_doc.o
 COBJS-$(CONFIG_CMD_DTT) += cmd_dtt.o
 COBJS-y += cmd_eeprom.o
 COBJS-$(CONFIG_CMD_ELF) += cmd_elf.o
+COBJS-$(CONFIG_CMD_EXPR) += cmd_expr.o
 COBJS-$(CONFIG_CMD_EXT2) += cmd_ext2.o
 COBJS-$(CONFIG_CMD_FAT) += cmd_fat.o
 COBJS-y += cmd_fdc.o
common/cmd_expr.c new file +70 -0

70 lines not on this page · raw message

Signature · 1 line
1.5.3.8
#1 lore raw

PATCH v2 1/1 Add expr command

common/cmd_expr.c line 69

Quoted 8 lines · On Wed, 13 Feb 2008 09:54:31 -0600 (CST) Kumar Gala…
common/cmd_expr.c new file +8 -0
+}
+
+U_BOOT_CMD(
+	expr, 5, 0, do_expr,
+	"expr    - set environment variable as the result of eval expression\n",
+	"name value1 <op> value2\n"
+	"    - set environment variable 'name' to the result of the evaluated\n"
+	"      express specified by <op>.  <op> can be &, |, ^, +, -, *, /, %\n"

can we at least change the name to "setexpr" or something, so as not break forward compatibility with any future GNU syntax expr implementation?

Kim

author
#2 lore raw

PATCH v2 1/1 Add expr command

Quoted 18 lines · Kim Phillips
Quoted 11 lines · On Wed, 13 Feb 2008 09:54:31 -0600 (CST) Kumar Gala…
common/cmd_expr.c new file +5 -0
+}
+
+U_BOOT_CMD(
+	expr, 5, 0, do_expr,
+	"expr    - set environment variable as the result of eval  

expression\n",

(quoted diff) +2 -0
+	"name value1 <op> value2\n"
+	"    - set environment variable 'name' to the result of the  

evaluated\n"

(quoted diff) +1 -0
+	"      express specified by <op>.  <op> can be &, |, ^, +, -,  

*, /, %\n"

can we at least change the name to "setexpr" or something, so as not break forward compatibility with any future GNU syntax expr implementation?

ok. Waiting to here on wd's feeling about having this as part of the standard command set or not.

- k

#3 lore raw

PATCH v2 1/1 Add expr command

Quoted 7 lines · In message <[email protected]> you wrote:
Quoted 4 lines

can we at least change the name to "setexpr" or something, so as not break forward compatibility with any future GNU syntax expr implementation?

ok. Waiting to here on wd's feeling about having this as part of the standard command set or not.

Well, if you ask me, I'd just call it expr.... [I have to admit that this is for very egoistic reasons, namely being used to type "sete" fort setenv, which then would be require me to type one more character. And with my age you don't change such habits easily ;-) ]

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Uncontrolled power will turn even saints into savages. And we can all
be counted on to live down to our lowest impulses.
	-- Parmen, "Plato's Stepchildren", stardate 5784.3
#4 lore raw

PATCH v2 1/1 Add expr command

In reply to Kim Phillips

Hello!

Quoted 3 lines · Kim Phillips

can we at least change the name to "setexpr" or something, so as not break forward compatibility with any future GNU syntax expr implementation?

+1

Regards
Andreas Schweigstill

Signature · 5 lines
Dipl.-Phys. Andreas Schweigstill
Schweigstill IT | Embedded Systems
Schauenburgerstra?e 116, D-24118 Kiel, Germany
Phone: (+49) 431 5606-435, Fax: (+49) 431 5606-436
Mobile: (+49) 171 6921973, Web: http://www.schweigstill.de/