why should we not use cd command in shell scripts

  • sikago
  • Born
  • Born
  • No Avatar
  • Joined: Jul 27, 2004
  • Posts: 3
  • Status: Offline

Post August 10th, 2004, 9:11 pm

hi all,
i heard that, we should not use 'cd' command in shell scripts because of some reason. but no one could specifically say the reason, can anybody help me out with the reason for the same.

thanks in advance.
siva
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post August 10th, 2004, 9:11 pm

  • Daemonguy
  • Moderator
  • Web Master
  • User avatar
  • Joined: Jan 23, 2004
  • Posts: 2673
  • Loc: Somewhere outside the box in Sarasota, FL.
  • Status: Offline

Post August 11th, 2004, 6:08 am

I don't think the push is to not use cd, but instead to cd to a "safe" directory. Some exploits make use of the dir presently running, ergo if you cd to a safe dir such as /tmp, there's not much a nefarious individual can accomplish.
Of course, writing good code is a must as well. :)

There's also the issue of absolutes. Usually it's considered good form to write out your commands as absolutes, such as /usr/local/bin/myprog to start a particular program or place data. This makes it easier to follow, and does not rely on directory changes to perform. Less moving parts is always a "good thing". ;)

Cheers.
"It's always a long day, 86,400 won't fit into a short."

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 46 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.