Date: Tue, 03 Sep 2002 15:18:01 +1000 From: Tony Landells <ahl@austclear.com.au> To: Kirk Bailey <idiot1@netzero.net> Cc: "freebsd-questions@freebsd.org" <freebsd-questions@FreeBSD.ORG> Subject: Re: sh script question Message-ID: <200209030518.PAA08645@tungsten.austclear.com.au> In-Reply-To: Message from Kirk Bailey <idiot1@netzero.net> of "Tue, 03 Sep 2002 00:43:43 -0400." <3D743DFF.B1DE6C8A@netzero.net>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <ahl@austclear.com.au> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200209030518.PAA08645>