From owner-freebsd-questions@freebsd.org Sun Jun 5 20:21:21 2016 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 847E5B6B446 for ; Sun, 5 Jun 2016 20:21:21 +0000 (UTC) (envelope-from baho-utot@columbus.rr.com) Received: from cdptpa-oedge-vip.email.rr.com (cdptpa-outbound-snat.email.rr.com [107.14.166.225]) by mx1.freebsd.org (Postfix) with ESMTP id 4C3101E47 for ; Sun, 5 Jun 2016 20:21:20 +0000 (UTC) (envelope-from baho-utot@columbus.rr.com) Received: from [75.187.32.8] ([75.187.32.8:53073] helo=raspberrypi.bildanet.com) by cdptpa-oedge01 (envelope-from ) (ecelerity 3.5.0.35861 r(Momo-dev:tip)) with ESMTP id A3/DB-04697-FB984575; Sun, 05 Jun 2016 20:21:19 +0000 Received: from [192.168.1.40] (helo=baho-utot.bildanet.com) by raspberrypi.bildanet.com with esmtp (Exim 4.84) (envelope-from ) id 1b9eXv-0006kq-7L for freebsd-questions@freebsd.org; Sun, 05 Jun 2016 16:21:19 -0400 Subject: Re: sh[it] and What am I missing here? To: freebsd-questions@freebsd.org References: <57544c10.90e58c0a.cacbc.62fd@mx.google.com> <57545029.5060805@gmail.com> <6f157455-0bda-ef46-82dc-e97fb0c4a08b@columbus.rr.com> <5754550A.6020500@holgerdanske.com> <02a5bb3c-e19a-221c-d30f-0feacebbf928@columbus.rr.com> <20160605221320.ac3da346.freebsd@edvax.de> From: Baho Utot Message-ID: Date: Sun, 5 Jun 2016 16:21:19 -0400 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: <20160605221320.ac3da346.freebsd@edvax.de> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-RR-Connecting-IP: 107.14.168.118:25 X-Cloudmark-Score: 0 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Jun 2016 20:21:21 -0000 On 06/05/16 16:13, Polytropon wrote: > I'm not sure if it has been mentioned in an explicit way, so > allow me to pick up some lines and clarify: > > On Sun, 5 Jun 2016 12:46:46 -0400, Baho Utot wrote: >> login in as a user ( non root ) >> set >> SHELL is set to SHELL=/bin/sh >> Ok now try >> su - (give password) >> set >> SHELL=/bin/csh Ok that makes sense >> Now >> /bin/sh >> set >> SHELL=/bin/csh WTF? > This is to be expected. The variable $SHELL corresponds to the > "shell" field of /etc/passwd, which sets the login shell. When > you use "su -", you perform a login operation, so root gets > assigned the login shell as specified by /etc/passwd. > > Additionally, "su -" sets the environmental variables for the > root user and therefore overwrites possibly different settings > of the initial user; "su -m" preserves that user's environment. > > > >> login as root >> set >> SHELL=/bin/csh Ok that makes sense >> /bin/sh >> set >> SHELL=/bin/csh WTF? > Again, the same thing happens. If you execute /bin/sh, it will > inherit the environment previously set up by /bin/csh, which > also contains the $SHELL variable. > > Remember, $SHELL does not state which shell you are currently > using - instead, it contains the name of the login shell. > > > >> It looks to me ( if I am not missing something here ) >> That I can only get to sh by loging in as a user...Again WTF > If you want to interactively run sh (the Bourne shell equivalent > of FreeBSD, which is not a good dialog shell, but the system's > default scripting shell, as well as the dialog shell for the > limited maintenance mode / single user mode), just execute it. > > % sh > # _ > > For scripting use, /bin/sh is recommended over bash except you > really _really_ want to use bash-isms that sh does not implement. > In this case, make sure your script starts with "#!/usr/local/bin/bash" > (the default path after installation of bash from ports) or the > more convenient "#!/usr/bin/env bash" which will also work if you > force bash's install into /bin. > > However, you don't need to execute a shell script written for sh > from inside sh. It's just important that the following conditions > are met: (1st) "#!/bin/sh" is the first line, (2nd) the script is > executable (use "chmod +x " to set the x bit), and (3rd) the > script is at a location inside $PATH, the search path from where > executables are sourced. When you run csh, give the "rehash" command > after you've put something into a valid executable location, or just > specify the full path (use "./name" or "./name.sh" for the current > directory). > > > Looks like I need to reread how login/interactive shells are executed as I don't remember when .profiles and .shrc are executed/read