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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help required regarding Unix Signal k_bijitesh UNIX for Advanced & Expert Users 9 01-09-2007 03:44 AM
UNIX Internals, Help required... digdarshan High Level Programming 4 08-04-2005 03:54 AM
Coding Standard For Unix Shell Scripting!!! Omkumar Shell Programming and Scripting 1 03-28-2005 12:19 PM
UNIX PATH info required PLEASE HELP (I'm new to unix) akitachi UNIX for Dummies Questions & Answers 1 05-10-2002 02:37 PM
Unix Coding Standards himanshu_s UNIX for Dummies Questions & Answers 3 12-06-2001 04:34 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-01-2008
udiptya udiptya is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 24
Question Unix coding tip required

Hi!

Suppose I am at a location xyz:/abc1/abc2/abc3

Is it possible to move to another location xyz:/mnl1/mnl2/mnl3

by some coding within a script?
  #2 (permalink)  
Old 02-01-2008
ennstate ennstate is offline
Registered User
  
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
Didn't cd help you?

Thanks
Nagarajan G
  #3 (permalink)  
Old 02-01-2008
risby risby is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 11
Maybe you are confused by the fact that if you put a cd command into a file and then execute the file your working directory doesn't change.

This is because the script is executing in a subshell that inherits your current environment. When the script finishes any changes it made to its own environment are lost with it.

The answer is to execute the script within your current environment rather than in a subprocess. This is called sourcing the script due to the command "source" used to accomplish this in the csh. It's still called sourcing the script even though the syntax is simply to use a dot in ksh or bash.

So, if a file called script contains a cd command, then

. script

will change your current working directory.
  #4 (permalink)  
Old 02-02-2008
udiptya udiptya is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 24
Your answer is not very clear to me. Can you explain it with an example!
  #5 (permalink)  
Old 02-02-2008
risby risby is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 11
Quote:
Originally Posted by udiptya View Post
Your answer is not very clear to me. Can you explain it with an example!
If your current working directory is:

/abc1/abc2/abc3

and you want it to be /mnl1/mnl2/mnl3 then enter the command

cd /mnl1/mnl2/mnl3

This bit of your question "by some coding within a script?" is what I was trying to answer but I'm now assuming that you didn't know you could change directories without using a script.
  #6 (permalink)  
Old 02-04-2008
udiptya udiptya is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 24
I am able to do that. Thanks a lot for the support.
Sponsored Links
Closed Thread

Bookmarks

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 01:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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