Unix coding tip required


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Unix coding tip required
# 1  
Old 02-01-2008
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  
Old 02-01-2008
Didn't cd help you?

Thanks
Nagarajan G
# 3  
Old 02-01-2008
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  
Old 02-02-2008
Your answer is not very clear to me. Can you explain it with an example!
# 5  
Old 02-02-2008
Quote:
Originally Posted by udiptya
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  
Old 02-04-2008
I am able to do that. Thanks a lot for the support.Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Coding Style at UNIX.com forums

Hi, as I mentioned in this thread(https://www.unix.com/shell-programming-and-scripting/280737-awk-function-return-permutations-n-items-out-m.html), a helpful coding style may improve overall value and support for people who come here and want to learn things the participants from unix.com have... (2 Replies)
Discussion started by: stomp
2 Replies

2. Homework & Coursework Questions

UNIX script coding HW question

i am trying to write a script code in unix that will: 1. The problem statement, all variables and given/known data: display following menu to user: (A) Add (B) Subtract (C) Multiply (D) Divide (E) Modulus (F) Exponentiation (G) Exit Then ask user for choice (A-F). After taking... (5 Replies)
Discussion started by: renegade755
5 Replies

3. Shell Programming and Scripting

UNIX script coding help?

Unix script coding help? i am trying to write a code that will display following menu to user: (A) Add (B) Subtract (C) Multiply (D) Divide (E) Modulus (F) Exponentiation (G) Exit Then ask user for choice (A-F). After taking users choice ask user for two numbers and perform... (3 Replies)
Discussion started by: renegade755
3 Replies

4. IP Networking

rlogin questions (Unix Tip 3426 - June 26, 2012)

In the following Unix Tip from Unix Guru Universe, are there some typos? Specifically, should: "From hosts(user:deepak)" be "From host2(user:deepak)"? (I'm almost 100% certain it should) "rlogin hosts.domain.com -l paul" be "rlogin host2.domain.com -l paul"? Some related... (0 Replies)
Discussion started by: RandyKramer
0 Replies

5. UNIX for Dummies Questions & Answers

Unix coding for triggering informatica

Hi, I have very little knowledge with unix and pmcmd. I need help with a issue. I have to see whether a file has been dropped in a particular location/path. If the file dropped I have to check the last modified time, which should be greater than 8pmEST the prior day. If the file has been... (4 Replies)
Discussion started by: redwolves
4 Replies

6. Solaris

Getting Started in UNIX - incorporating C coding

I'm just starting a 'serious' coding in UNIX, so what I need is to run a C code on UNIX, What do I have to install (app) prior to coding/running the code and how do I compile that code? can I write my c code in UNIX or I need to have a visual studio for this? (7 Replies)
Discussion started by: Peevish
7 Replies

7. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

8. UNIX for Advanced & Expert Users

Problem with tip utility in unix

Hi , I have wrote a telnet clinet application to interact with remote system . This program takes the screen shots for every interaction and send back to us. After connecting to remote machine , i want to call tip utility to interact with a device which is connected to one remote system. Now my... (0 Replies)
Discussion started by: prasadvsda
0 Replies

9. Shell Programming and Scripting

Coding Standard For Unix Shell Scripting!!!

Is there any site on Coding Standard for Shell Scripting in UNIX. Please help me know!!!!! Thanks Om (1 Reply)
Discussion started by: Omkumar
1 Replies

10. UNIX for Dummies Questions & Answers

Unix Coding Standards

Hi, I am looking for some coding standards for Unix Shell Scripting. Can anyone help me out in this? Regards, Himanshu (3 Replies)
Discussion started by: himanshu_s
3 Replies
Login or Register to Ask a Question