Web lists-archives.com

Re: bash usage.




On Thu, Oct 26, 2017 at 04:19:42PM +1100, David Margerison wrote:
> On 26 October 2017 at 11:39,  <peter@xxxxxxxxxxx> wrote:
> >
> > According to 'man mountpoint', it returns 0 if something is mounted.
> > So why the complaint from
> >   if [ mountpoint $WorkingDirectory ] ?
> 
> Answered here:
> 
> http://mywiki.wooledge.org/BashPitfalls#if_.5Bgrep_foo_myfile.5D
> 
> http://mywiki.wooledge.org/BashGuide/TestsAndConditionals#Conditional_Blocks_.28if.2C_test_and_.5B.5B.29
> 
> On 26 October 2017 at 12:23, Roberto C. Sánchez <roberto@xxxxxxxxxx> wrote:
> >
> > mountpoint -q $WorkingDirectory
> > if [[ $? = 0 ]]
> 
> That will work, but is ridiculous considering this works by design:
> 
> if mountpoint -q "$wd" ; then
>   echo "$wd is a mountpoint"
> fi
> 

Yes, quite right.  Though, my syntax makes it clear that what is being
tested/evlauated is the exit status, not the output.  I know that the if
evaluates the exit status, but that may not be immediately evident to
someone who is not particularly familiar with shell programming.  

To each his own.

Regards,

-Roberto

-- 
Roberto C. Sánchez