From owner-freebsd-questions Mon Sep 2 22:18:25 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3AE0437B400 for ; Mon, 2 Sep 2002 22:18:12 -0700 (PDT) Received: from ns2.austclear.com.au (ns2.austclear.com.au [192.43.185.70]) by mx1.FreeBSD.org (Postfix) with ESMTP id B4F5843E72 for ; Mon, 2 Sep 2002 22:18:10 -0700 (PDT) (envelope-from ahl@austclear.com.au) Received: from tungsten.austclear.com.au (tungsten.austclear.com.au [192.168.166.65]) by ns2.austclear.com.au (8.11.2/8.11.3) with ESMTP id g835I2t70054; Tue, 3 Sep 2002 15:18:02 +1000 (EST) (envelope-from ahl@austclear.com.au) Received: from tungsten (tungsten [192.168.166.65]) by tungsten.austclear.com.au (8.9.3/8.9.3) with ESMTP id PAA08645; Tue, 3 Sep 2002 15:18:02 +1000 (EST) Message-Id: <200209030518.PAA08645@tungsten.austclear.com.au> X-Mailer: exmh version 2.1.1 10/15/1999 To: Kirk Bailey Cc: "freebsd-questions@freebsd.org" Subject: Re: sh script question In-Reply-To: Message from Kirk Bailey of "Tue, 03 Sep 2002 00:43:43 -0400." <3D743DFF.B1DE6C8A@netzero.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 03 Sep 2002 15:18:01 +1000 From: Tony Landells Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi Kirk, idiot1@netzero.net said: > I want to write a script to install a python application. I has to > locate the interpreter, extract that path, and create the shebang > declaration on the first line, then append the remaining prepared > script to that, create a directory under the web cgi-bin, and create a > pair of files in it with the owner's email (and password in one of > them). some of this is simple io, but I am pretty unclear on the > joining of strings and variable values, not to mention parsing the > output of whereis- or how to direct it's raw results into some sort of > a variable. Scripting can be very powerful, but I'm still something of > a newbie at this. Anyone interested in tossing an oar into my waters? $ whereis python python: /usr/local/bin/python # While I know that if we find the python interpreter it will be the # second word of the result (as in "python: /usr/local/bin/python") # let's try to allow for things where people have somehow fouled it up. for i in `whereis -b python`; do [ -f $i ] && python=$i # found something real done if [ -z "$python" ]; then echo "Can't find python interpreter!\n" exit 1 fi As for joining strings and variables together, it's not that hard: $ testvar="test" $ echo $testvar test $ echo var$testvar vartest $ echo $testvar.var test.var $ echo $testvarvar $ echo "$testvar"var testvar $ echo ${testvar}var testvar Basically you can join a variable value straight on to something else. You can also join something directly on to the end of a variable if the thing you join on couldn't be part of a variable name. The only time you run into problems are when the following characters are legal for variable names. In that case you need to tell the shell where the variable name ends. As you can see above, you can get away with quotes to achieve this. In some circumstances you may want quoting to achieve some other goal, though, so it's not foolproof and nested quoting gets very hard to understand. Putting the variable name in braces is, in my opinion, the correct way to do it. I hope that helps! Tony -- Tony Landells Senior Network Engineer Ph: +61 3 9677 9319 Australian Clearing Services Pty Ltd Fax: +61 3 9677 9355 Level 4, Rialto North Tower 525 Collins Street Melbourne VIC 3000 Australia To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message