From mboxrd@z Thu Jan 1 00:00:00 1970 From: Harald Seiler Date: Wed, 08 Apr 2020 14:51:21 +0200 Subject: Basic syntax question In-Reply-To: References: Message-ID: <26043161afa22075706769ec9ec0cdbd1a59b7bf.camel@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hello Damien, On Wed, 2020-04-08 at 11:27 +0300, Damien LEFEVRE wrote: > Hi, > > I'm new to u-boot. I'm trying to store the return value of gpio command to > a variable. > > I have the following, (switch released): > Tegra186 (P2771-0000-500) # gpio input FF1 > gpio: pin FF1 (gpio 241) value is 1 > Tegra186 (P2771-0000-500) # setexpr X 'gpio input FF1' > Tegra186 (P2771-0000-500) # echo $X > 0 > > But I'm expecting X to be 1, the return value of gpio. What you want to do is look at the return value of the gpio command. The return value in U-Boot is stored in a variable $?, similar to POSIX shells. As this variable is always the return value of the last command, you have to save its value immediately after running `gpio input`: => gpio input FF1 => setenv X $? Afterwards, you can continue however you like, e.g. => echo $X > If I press the switch I see the value change to 0, so I know the gpio state > changes > Tegra186 (P2771-0000-500) # gpio input FF1 > gpio: pin FF1 (gpio 241) value is 0 > > Thanks, > -Damien Hope this helps! -- Harald