why should we not use cd command in shell scripts

  • sikago
  • Born
  • Born
  • sikago
  • Posts: 3

Post 3+ Months Ago

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
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Daemonguy
  • Moderator
  • Web Master
  • User avatar
  • Posts: 2700
  • Loc: Somewhere outside the box in Sarasota, FL.

Post 3+ Months Ago

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.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 23 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.