From owner-freebsd-questions@freebsd.org Fri Jun 5 12:26:48 2020 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8368F32A01A for ; Fri, 5 Jun 2020 12:26:48 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mout.kundenserver.de", Issuer "TeleSec ServerPass Class 2 CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49dhj33TFDz4vlQ for ; Fri, 5 Jun 2020 12:26:47 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r56.edvax.de ([178.8.33.179]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPA (Nemesis) id 1M9npT-1je9AH410n-005osg; Fri, 05 Jun 2020 14:26:45 +0200 Date: Fri, 5 Jun 2020 14:26:44 +0200 From: Polytropon To: dwilde1@gmail.com Cc: freebsd-questions Subject: Re: Mininal skills Message-Id: <20200605142644.add4cf07.freebsd@edvax.de> In-Reply-To: References: <20200605062217.cjtkdgwqwqqienct@blueeyes.stuffed.animals> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:LSv/Pr4Y0920bK1KndwXHk7aB+D3ZphqGCGSEG6D7ZtqN1Mz3Z2 kK6MF1Id8rXIgk48exEdBfJl27YvWsUcRqqjU8c84xdbTycHtcRTlVaOEA8DctSWbyhFU9q H6mPDwiNFxohrJhtDFsYdIyKjdR1SqKE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-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=none (mx1.freebsd.org: domain of freebsd@edvax.de has no SPF policy when checking 217.72.192.74) smtp.mailfrom=freebsd@edvax.de X-Spamd-Result: default: False [1.27 / 15.00]; HAS_REPLYTO(0.00)[freebsd@edvax.de]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; MV_CASE(0.50)[]; HAS_ORG_HEADER(0.00)[]; NEURAL_HAM_SHORT(-0.42)[-0.421]; RCPT_COUNT_TWO(0.00)[2]; FREEMAIL_TO(0.00)[gmail.com]; RECEIVED_SPAMHAUS_PBL(0.00)[178.8.33.179:received]; RCVD_TLS_LAST(0.00)[]; R_DKIM_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:8560, ipnet:217.72.192.0/20, country:DE]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.62)[-0.616]; REPLYTO_EQ_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-0.09)[-0.093]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[edvax.de]; AUTH_NA(1.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MID_CONTAINS_FROM(1.00)[]; RCVD_IN_DNSWL_NONE(0.00)[217.72.192.74:from]; R_SPF_NA(0.00)[no SPF record]; RWL_MAILSPIKE_POSSIBLE(0.00)[217.72.192.74:from]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Jun 2020 12:26:48 -0000 On Fri, 5 Jun 2020 04:27:20 -0700, Donald Wilde wrote: > On 6/4/20, Michael Schuster wrote: > > On Fri, Jun 5, 2020 at 8:22 AM Brenda J. Butler wrote: > > > >> > >> As for "what is shell programming" ... it's the same as regular > >> programming > >> but written in a language that doesn't need to be compiled. Often the > >> shell program calls on other programs to do the work. So learning "shell > >> programming" is about more than learning the shell language - it is > >> also about learning enough of those other little utilities to be > >> able to do something useful in the shell. > >> > > > > One of the best books on the subject (in my experience) is "The Unix > > Programming Environment" by Kernighan and Pike - written in 1984, it is > > still a good text to teach you some of the fundamentals of the ... unix > > programming environment ;-). > > I highly recommend it. > [snip] > > I agree! Very good book! Another good one is 'UNIX Network > Programming' by Stevens, and soon enough you'll be ready for 'Advanced > Programming in the UNIX Environment', also by Stevens (Sorry, I'm a > 'dead tree' addict!). Dead tree: "The magic garden explained. The internals of UNIX System 5 release 4." by Benny Goodheart & James Cox, if you want to dive into system programming. > While compiled binaries on 'NIX systems like FreeBSD are distributed > in ELF format (which you can look up if you are interested), files > intended for a scripting language such as a shell have a very special > sequence of characters the shell looks for at the beginning: '#!', > also called 'she-bang'. These MUST be the first two characters in the > text file, followed by the location of the program you want to use to > execute the file, such as '#!/usr/local/bin/ruby27' for the latest > version of Ruby. This is needed (and generally recommended) for files that have the executable attribute set, so you can run the script as if it was a real program - except that you implicitely call the appripriate interpreter, indicated by the #! line, that will interpret the script. Related terminology: interpreter, compiler. Further words: compiler, assembler, preprocessor, linker. > You can also specify a different shell binary as your > program. For example, I execute a file with '#!/bin/sh' with the > simple Bourne shell 'sh' from my root prompt when root's normal shell > (on FreeBSD) is tcsh. The syntax of each shell's language is somewhat > different, so take care. Just dive in with your text editor, create a > few files, and try to run them. If you haven't already, use 'chmod + x > myfile' to make them run directly from the prompt, like: > > ./myscript > > the period-slash combo tells your shell that the current directory is > where to find that file; otherwise, it'll merrily look for your > program in /bin, /usr/bin, etc. Sidenote: The command is chmod +x No space after "+"; surely just a typo. If you forgot to make the file executable, you can still have sh process it: sh myscript The extension ".sh" for shell scripts is of course optional. It is not entirely uncommon that scripts which have the executable bit set and are intended to be run directly do not have an extension, while scripts to be called with the interpreter do keep the extension, for example: ./something is an awk script, it starts with "#!/usr/bin/awk -f", while somethingelse.awk is to be used like this: blah | foo | awk -f somethingelse.awk > results.txt As mentioned, a #! line doesn't have to exist in such a case. This isn't exactly a rule, but you will often find it in reality. Of course there's nothing wrong with doing things like ./thescript.sh if it is set executable. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...