From owner-freebsd-questions@freebsd.org Wed Feb 1 16:23:29 2017 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 8C2C5CCBBE6 for ; Wed, 1 Feb 2017 16:23:29 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mailrelay13.qsc.de (mailrelay13.qsc.de [212.99.187.253]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.antispameurope.com", Issuer "TeleSec ServerPass DE-2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D844716F1 for ; Wed, 1 Feb 2017 16:23:28 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de ([213.148.129.14]) by mailrelay13.qsc.de; Wed, 01 Feb 2017 17:25:17 +0100 Received: from r56.edvax.de (port-92-195-126-61.dynamic.qsc.de [92.195.126.61]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id EBCC63CCFF; Wed, 1 Feb 2017 17:23:13 +0100 (CET) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id v11GNDLH002007; Wed, 1 Feb 2017 17:23:13 +0100 (CET) (envelope-from freebsd@edvax.de) Date: Wed, 1 Feb 2017 17:23:13 +0100 From: Polytropon To: Roger Pate Cc: "freebsd-questions@freebsd.org" Subject: Re: Variable assignment in sh Message-Id: <20170201172313.3a3eee93.freebsd@edvax.de> In-Reply-To: References: <20170131161824.a9f1ef46.freebsd@edvax.de> <20170131185103.7f911dfb.freebsd@edvax.de> <5f51e2c3bdb8a20c6a7786c2b345c957.squirrel@webmail.harte-lyne.ca> <20170201014858.eec196d0.freebsd@edvax.de> 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-cloud-security-sender: freebsd@edvax.de X-cloud-security-recipient: freebsd-questions@freebsd.org X-cloud-security-Virusscan: CLEAN X-cloud-security-disclaimer: This E-Mail was scanned by E-Mailservice on mailrelay13.qsc.de with 8712769E519 X-cloud-security-connect: mx01.qsc.de[213.148.129.14], TLS=1, IP=213.148.129.14 X-cloud-security: scantime:.7032 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Feb 2017 16:23:29 -0000 On Wed, 1 Feb 2017 10:06:33 -0500, Roger Pate wrote: > On Tue, Jan 31, 2017 at 8:26 PM, Manish Jain > wrote: > > A point here for bash scripting. > > Most often, but not always, if I need something bash has and /bin/sh > lacks, it's time to write that script in a different language. :P Don't confuse sh with bash, they're not fully interchangeable. While sh ("classic Bourne shell") is quite portable and usually POSIX, bash is not. Even on Linux, sometimes bash != bash, and sometimes it's dash. You can see bash as a superset of sh, so you can do testing of sh scripts with bash quite well, even in the "line by line" interactive manner. If you need stuff to work across different operating systems, sh is often called "lowest common denominator" as most UNIX systems default to it as scripting shell. If you need "bash-isms" (features that bash has, but sh doesn't), there are also some portable ways to deal with the shebang line, but don't assume that bash is installed everywhere as /bin/bash. :-) Of course you are right: When you reach the border of what a shell language can do, consider using better tools, more suitable for the task you want to solve. For example, if you find yourself in a while read something | cut | cut | sed | grep | sed | sort piping chain, consider using awk. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...