Date: Tue, 7 Nov 2006 10:43:11 -0800 From: Bill Campbell <freebsd@celestial.com> To: freebsd-questions@freebsd.org Subject: Re: 'cd' ing inside a shell script Message-ID: <20061107184311.GA24748@ayn.mi.celestial.com> In-Reply-To: <00ff01c7027a$36263dd0$6501a8c0@GRANT> References: <00ff01c7027a$36263dd0$6501a8c0@GRANT>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20061107184311.GA24748>