You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2023/01/12 19:05:46 UTC

[GitHub] [nuttx] acassis opened a new issue, #8097: CONFIG_NSH_CMDPARMS not working

acassis opened a new issue, #8097:
URL: https://github.com/apache/nuttx/issues/8097

   According with documentation, NSH Optional Syntax Extensions from here: https://nuttx.apache.org/docs/10.0.0/components/nsh/nsh.html
   
   We should be able to set parameter with return of commands:
   
   "
   CONFIG_NSH_CMDPARMS: If selected, then the output from commands, from file applications, and from NSH built-in commands can be used as arguments to other commands. The entity to be executed is identified by enclosing the command line in back quotes. For example:
   
   set FOO myprogram $BAR
   "
   
   However it is not working as expected.
   
   I decided to do a simple test: just get the output of "hello" command.
   
   Confirm we have hello command working:
   
   ```
   nsh> hello
   Hello, World!!
   ```
   Set HEY with the result of hello
   
   ```
   nsh> set HEY hello
   ```
   
   Hmm, not what I was expecting:
   
   ```
   nsh> echo $HEY
   hello
   ```
   
   Ok, let try with braces:
   
   ```
   nsh> echo ${HEY}
   hello
   ```
   Nop...
   
   Let try to execute HEY passing it to $( ) as we do on bash:
   
   ```
   nsh> echo $(HEY)
   ```
   
   Printed "nothing"
   
   Let to execute the content of HEY
   
   ```
   nsh> echo `${HEY}`
   nsh: hello: open failed: 2
   nsh: ``: exec failed: 2
   ```
   
   It tried to execute the hello command but failed with error 2 ("No such file or directory")
   
   I have all necessary options enabled:
   
   ```
   CONFIG_NSH_CMDPARMS=y
   CONFIG_NSH_QUOTE=y
   CONFIG_NSH_ARGCAT=y
   ```
   
   After some investigation I discovered that our documentation is wrong, we need single back quote surrounding our command:
   
   ```
   /****************************************************************************
    * Name: nsh_parse_cmdparm
    *
    * Description:
    *   This function parses and executes a simple NSH command.  Output is
    *   always redirected.  This function supports command parameters like
    *
    *     set FOO `hello`
    *
    *   which would set the environment variable FOO to the output from
    *   the hello program
    *
    ****************************************************************************/
   ```
   
   But, of course the result is the same:
   
   ```
   nsh> set FOO `hello`
   nsh: hello: open failed: 2
   nsh: ``: exec failed: 2
   ```
   
   Enabling the debug I found the root causes:
   
   ```
   nsh> set FOO `hello`
   nxspawn_open: Open'ing path=/tmp/TMP1.dat oflags=0026 mode=01a4
   nxspawn_open: ERROR: open failed: -2                        
   exec_builtin: ERROR: task_spawn failed: 1                   
   The nsh_builtin() resulted = -1
   nsh: hello: open failed: 2
   nsh: ``: exec failed: 2
   ```
   
   It is trying to create a temporary file at /tmp.
   
   I don't know if it was required in the past, the documentation said nothing about it.
   
   Mounting a RAMDISK at /tmp fixed the issue:
   
   ```
   nsh> mkrd 64
   nsh> mkfatfs /dev/ram0
   nsh> mount -t vfat /dev/ram0 /tmp
   
   nsh> set FOO `hello`
   
   nsh> echo $FOO
   Hello, World!!
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] acassis closed issue #8097: CONFIG_NSH_CMDPARMS not working

Posted by GitBox <gi...@apache.org>.
acassis closed issue #8097: CONFIG_NSH_CMDPARMS not working
URL: https://github.com/apache/nuttx/issues/8097


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 closed issue #8097: CONFIG_NSH_CMDPARMS not working

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 closed issue #8097: CONFIG_NSH_CMDPARMS not working
URL: https://github.com/apache/nuttx/issues/8097


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] acassis commented on issue #8097: CONFIG_NSH_CMDPARMS not working

Posted by GitBox <gi...@apache.org>.
acassis commented on issue #8097:
URL: https://github.com/apache/nuttx/issues/8097#issuecomment-1380883196

   So, it requires CONFIG_LIBC_TMPDIR enabled, but there is no information about it in any place.
   I think we could select CONFIG_LIBC_TMPDIR when CONFIG_NSH_CMDPARMS or CONFIG_NSH_QUOTE is enabled


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] acassis commented on issue #8097: CONFIG_NSH_CMDPARMS not working

Posted by GitBox <gi...@apache.org>.
acassis commented on issue #8097:
URL: https://github.com/apache/nuttx/issues/8097#issuecomment-1381020405

   Some "funny" thing:
   ```
   nsh> set WIFI `cat /mnt/esp/wifi/wifi.nvs.net80211.sta.ssid`
   nsh> echo $WIFI
   
   nsh> cat /mnt/esp/wifi/wifi.nvs.net80211.sta.ssid
   MyRouternsh>
    
   nsh> set PASS `cat /mnt/esp/wifi/wifi.nvs.net80211.sta.pswd`
   nsh> echo $PASS
   MyPassword
   nsh>
   
   nsh> cat /mnt/esp/wifi/wifi.nvs.net80211.sta.pswd
   MyPasswordsh>
   ```
   
   No idea why it fails to get the ssid and works to get the password


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org