sh[it] and What am I missing here?

jd1008 jd1008 at gmail.com
Sun Jun 5 18:26:51 UTC 2016



On 06/05/2016 11:40 AM, Ernie Luzar wrote:
> Baho Utot wrote:
>> On 06/05/16 12:31, David Christensen wrote:
>>> On 06/05/2016 08:38 AM, Baho Utot wrote:
>>> ...
>>>> root at baho-utot:~ # set
>>> ...
>>>> shell   /bin/csh
>>> ...
>>>> tcsh    6.18.01
>>> ...
>>>> OK tcsh as I thought
>>> ...
>>>> OK switch shells
>>>>
>>>> root at 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:
>>
>> 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
>
> I think your problem is where you are placing your script.
> You have to place your script in a path that is auto searched for 
> executable scripts.
>
> Place your script in /usr/local/bin on your development pc and on the 
> new installed os pc. Then just entering the script on the console 
> command line will cause it to execute.  BY the way your script doesn't 
> need to be suffixed with .sh to work.
Hey Baho,
Well, your login rc files (such as .cshrc or whatever other rc or 
profies files are executed,
they set your default shell to (as you indicated) /bin/csh.
Since you do not want to change that, then I suggest that your shell 
script you are working
with have this code just after the shebang line:

export SHELL=/bin/sh

then code you functions and script after that.

The shell variable value will only affect the shell you are executing 
and any other
shell scripts you run from there (as long as those shell scripts are 
shebanged with
#!/bin/sh
and do not reset the SHELL variable value.

HTH



More information about the freebsd-questions mailing list