From owner-freebsd-questions@FreeBSD.ORG Tue Nov 7 18:42:46 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org 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 1370E16A5CF for ; Tue, 7 Nov 2006 18:42:45 +0000 (UTC) (envelope-from bill@ayn.mi.celestial.com) Received: from ayn.mi.celestial.com (hayek.celestial.com [192.136.111.12]) by mx1.FreeBSD.org (Postfix) with ESMTP id AF14243EEC for ; Tue, 7 Nov 2006 18:41:36 +0000 (GMT) (envelope-from bill@ayn.mi.celestial.com) Received: from localhost (localhost [127.0.0.1]) by ayn.mi.celestial.com (Postfix) with ESMTP id 5AF336860D097; Tue, 7 Nov 2006 10:43:11 -0800 (PST) X-Virus-Scanned: amavisd-new at mi.celestial.com Received: from ayn.mi.celestial.com ([127.0.0.1]) by localhost (ayn.mi.celestial.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 3VSUOepy1hUw; Tue, 7 Nov 2006 10:43:11 -0800 (PST) Received: by ayn.mi.celestial.com (Postfix, from userid 203) id 38F2F6860B903; Tue, 7 Nov 2006 10:43:11 -0800 (PST) Date: Tue, 7 Nov 2006 10:43:11 -0800 From: Bill Campbell To: freebsd-questions@freebsd.org Message-ID: <20061107184311.GA24748@ayn.mi.celestial.com> Mail-Followup-To: freebsd-questions@freebsd.org References: <00ff01c7027a$36263dd0$6501a8c0@GRANT> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <00ff01c7027a$36263dd0$6501a8c0@GRANT> User-Agent: Mutt/1.5.11 OpenPKG/2.5 Subject: Re: 'cd' ing inside a shell script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd@celestial.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Nov 2006 18:42:46 -0000 On Tue, Nov 07, 2006, Grant Peel wrote: >Hi all, >Some of my webmail users are using lots of disk space. >I want to make a shell script, like so: >cd /home/webmail/public_html/cgi-bin/etc/users ; du -h -d1 | grep M | sort >-nr -k1 >and run it daily in a cronjob, mailing the results to my assistants. >with the 'cd' at that start of the script have any adverse affect on the >rest of the system or cronjobs? OK, will the scripot just complete and >exit, with the 'cd' having no affect? A cd inside a script will have no effect on anything outside of the script. Only brain-dead systems from Microsoft do that. In fact, within a script, there's a safe way to do cd's that doesn't affect the directory which can be very handy when writing scripts that may not want to keep track of where they are: #!/bin/sh # do something here ( cd somedirecotry # you're now in somedirectory to do something ) # now you're back in the original directlry. A new shell is spawned for the process inside the parenthesis, and any directory changes etc. will have no effect outside the parenthesis. Bill -- INTERNET: bill@Celestial.COM Bill Campbell; Celestial Software LLC URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676 When a place gets crowded enough to require ID's, social collapse is not far away. It is time to go elsewhere. The best thing about space travel is that it made it possible to go elsewhere. -- Robert Heinlein