Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Jun 2016 00:01:09 +0100
From:      RW <rwmaillists@googlemail.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: sh[it] and What am I missing here?
Message-ID:  <20160606000109.3141550d@gumby.homeunix.com>
In-Reply-To: <4daed7a2-9a0b-15d9-0bb2-31227f8fcddd@columbus.rr.com>
References:  <31b2cfb1-1da8-9262-3f03-d964776c905e@columbus.rr.com> <575453F9.9070508@holgerdanske.com> <4daed7a2-9a0b-15d9-0bb2-31227f8fcddd@columbus.rr.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 5 Jun 2016 13:15:25 -0400
Baho Utot wrote:

> On 06/05/16 12:31, David Christensen wrote:
> > On 06/05/2016 08:38 AM, Baho Utot wrote:
> > ...  
> >> root@baho-utot:~ # set  
> > ...  
> >> shell   /bin/csh  
> > ...  
> >> tcsh    6.18.01  
> > ...  
> >> OK tcsh as I thought  
> > ...  
> >> OK switch shells
> >>
> >> root@baho-utot:~ # /bin/sh
> >> # set  
> > ...  
> >> Why is the SHELL variable still set to /bin/csh  
> > ...
> >
> > Because you are invoking a program (/bin/sh) and that program did
> > not modify the SHELL environment variable.
> >
> >
> > On 06/05/2016 09:15 AM, jd1008 wrote:  
> > > Do I understand correctly that you want bash to be your shell?
> > > If so, you can run (as root), the command
> > > chsh <username>  
> >
> > +1
> >
> > Take a look at:
> >
> > https://www.freebsd.org/doc/en/articles/linux-users/shells.html
> >
> >
> > David  
> 
> I understood that, But I do not want to change the default shell.
> I only want to create a script ( sh script ) and run if from a clean 
> machine with just base install nothing else and then run my sh script
> to build some ports.  That's were the trouble lies.  ie functions not 
> returning status for example:

It doesn't work because the shell script is wrong. [ func ] doesn't
execute func. func and "]" are actually arguments to "[". Using
backticks around func executes it.
 

See man test for the rest.


$ cat /tmp/foo
#!/bin/sh

func() {
     echo "Yep its me"
     return 1
}

if ! func  ; then
     echo "This works"
fi


if [ "`func`" = "Yep its me" ]  ; then
     echo "This works too"
fi


if [ "`func`"  ]  ; then
     echo "And this works also"
fi

$  /tmp/foo
Yep its me
This works
This works too
And this works also





> test.sh
> chmod +x test.sh
> 
> #!/bin/sh
> 
> func() {
>      echo "Yep it's me"
>      return 1
> }
> 
> if [ func ] ; then                 # if [ 1 = func ] or if [ 1 -eq
> func ] doesn't work either
>      echo "This works"
> fi
> 
> ./test.sh
> 
> [: func: unexpected operator
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to
> "freebsd-questions-unsubscribe@freebsd.org"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160606000109.3141550d>