5

Currently my boot string (displayed with env print) is:

If I want to set a variable to a string in u-boot, I do

env set variable 'my string'

But what to do if the string contains the quote characters? I want to put the following into bootcmd:

if test ${jpsdboot} = 'on' ; then run sdboot; else run emmcboot; fi;

If I put the whole string in quotes (either ' or "), it works but the quotes around 'on' are missing.

If I put it with \'on\' it generates a syntax error.

If I put it without quotes, it executes the part after ; immediately.

How to get the quote marks into the variable value?

Additional info:

What env print returns on a "pristine" board:

 bootcmd=run usbprod; if test ${jpsdboot} = 'on' ; then run sdboot; else run emmcboot; fi;

What my various tries produced:

 U-Boot > env set bootcmd 'run usbprod; if test ${jpsdboot} = 'on' ; then run sdboot; else run emmcboot; fi;'
 bootcmd=run usbprod; if test ${jpsdboot} = on ; then run sdboot; else run emmcboot; fi;

 U-Boot > env set bootcmd 'run usbprod; if test ${jpsdboot} = \'on\' ; then run sdboot; else run emmcboot; fi;'
 syntax error

 U-Boot > env set bootcmd run usbprod; if test ${jpsdboot} = 'on' ; then run sdboot; else run emmcboot; fi; 
 Booting from the SD card ...

 U-Boot > env set bootcmd "run usbprod; if test ${jpsdboot} = 'on' ; then run sdboot; else run emmcboot; fi;"
 bootcmd=run usbprod; if test on = on ; then run sdboot; else run emmcboot; fi;

  U-Boot > env set bootcmd "run usbprod; if test ${jpsdboot} = \\'on\\' ; then run sdboot; else run emmcboot; fi;"
  bootcmd=run usbprod; if test on = \\on ; then run sdboot; else run emmcboot; fi;

  U-Boot > env set bootcmd "run usbprod; if test \${jpsdboot} = \'on\' ; then run sdboot; else run emmcboot; fi;"
  bootcmd=run usbprod; if test \\${jpsdboot} = \\'on\\' ; then run sdboot; else run emmcboot; fi;

  U-Boot > env set bootcmd 'run usbprod; if test ${jpsdboot} = \\'on\\' ; then run sdboot; else run emmcboot; fi;'
  bootcmd=run usbprod; if test ${jpsdboot} = \\on\\ ; then run sdboot; else run emmcboot; fi;
  • You forgot to show the boot string displayed by env print. Are you saying that "if test ${jpsdboot} = 'on' ; then run sdboot; else run emmcboot; fi;" fails? What if you switch the quotes around and try 'if test ${jpsdboot} = "on" ; then run sdboot; else run emmcboot; fi;' ? – terdon Mar 27 '15 at 13:11
  • @terdon: The original string uses single quotes there, It's exactly what I wrote I wanted to put in there. Maybe I can get double quotes in, but that's not what I want; I want to restore the original. I can give the actual results for the rest... – SF. Mar 27 '15 at 13:17
  • I know, I was just suggesting switching them around as a workaround that might let you do what you want. I'm very surprised that using " fails though. That makes no sense. In any case, please add the missing line to the beginning of your question. – terdon Mar 27 '15 at 13:19
  • Actually, the comparison without quotes works, but I'd still like to know how to get these quotes in. – SF. Mar 27 '15 at 14:12
1

The following works for me:

U-Boot> setenv bootcmd 'if test ${jpsdboot} = ' \''on'\' '; then run sdboot; else run emmcboot; fi;'

I found this by trial and error. It looks like you need to end the single-quoted string, then add the escaped singe-quote character and open single-quoted string again to continue with your string.

Tested: U-Boot 2015.04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.