The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
getting : No such file or directory while executing a shell script ananthi_ku Shell Programming and Scripting 7 10-10-2008 09:08 AM
Change directory command (cd) c00kie88 Shell Programming and Scripting 21 07-11-2008 10:01 AM
Executing script's directory jasony001 Shell Programming and Scripting 2 03-03-2008 02:48 AM
Monitoring a directory for new files with .xx and executing command if found krkan Shell Programming and Scripting 4 03-14-2006 11:16 PM
Change directory command (cd) oscarr Shell Programming and Scripting 4 08-23-2002 08:30 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-27-2009
samplify samplify is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 4
Lightbulb CD (change directory) - Not advisable for executing a command

Hi,

This is a quick one.
I have got a review comment in one of the scripts that i wrote:

"In UNIX script it not advisable to use cd to a directory and then run command."

Is this true?
I was trying to cd to log directory and use some cat or head or ls command.

Many Thanks,
Sam
  #2 (permalink)  
Old 05-27-2009
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,318
Well, this is partially true. You may get confused when executing the script from another location or you may need to navigate back to the original folder.
You should rather use the full path to the file, i.e. 'cat /home/bob/test.txt'
Example :
Code:
cd /folder/test/
cat file1.txt
cd - 
# return to the last folder, variable kept in ENV as OLDPWD.
# or 
cd /home/bob/test/firstfolder/secondfolder/
cat somefile.txt
You can simply avoid all those 'cd' commands by just using the full path to the file.
  #3 (permalink)  
Old 05-27-2009
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2005
Location: Switzerland - GE
Posts: 1,546
another reason is you may be victim of spoofing (if . is in the PATH...) and other side effects (often with JAVA stuff...) like a program runs when you cd to the directory but fails when called from elsewhere (environment issue)...
Sponsored Links
Reply

Bookmarks

Tags
cd not advisable

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 09:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0