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
Hard Drive Question Netghost AIX 0 08-24-2006 01:01 PM
hard/soft link question Browser_ice UNIX for Dummies Questions & Answers 1 08-19-2006 02:13 AM
Ok simple question for simple knowledge... Corrail UNIX for Dummies Questions & Answers 1 11-28-2005 01:03 PM
Please Help.... Desperate need! Hard Question! Sparticus007 UNIX for Advanced & Expert Users 1 01-11-2002 06:43 PM
Experts Only! Hard Question Ahead!!!! Foo49272 UNIX for Advanced & Expert Users 1 01-07-2002 10:22 PM

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

Join Date: Dec 2007
Posts: 6
Simple question (for you guys, hard for me)

I am trying to exit this script by cd'ing into a particular directory.

#!/bin/bash
/opt/xxx/xxx/d2h $1
fname=$( /opt/xxx/xxx/d2h $1)
cd /opt/xxx1/xxx1
find . -name '*'$fname'*' -ls
cd /opt/xxx1/xxx1

Upon execution, it returns to my home directory (where I am running this script from.

The last line cd/opt/xxx1/xxx1 doesnt work for me and I cant figure out why it isnt.


Any help would be appreciated. Thanks in advance.
  #2 (permalink)  
Old 01-07-2008
ajcannon ajcannon is offline
Registered User
  
 

Join Date: Aug 2007
Location: Binfield, Berkshire. UK
Posts: 91
Try adding -xv to the end of your first line - the /bin/bash one.

It will run the shell in debug(ish) mode but what is useful is it shows you what the variables are set to. If /opt/XX1/XX1 doesn't exist then your last line effectively becoms just 'cd' - which *will* return you to your $HOME.

Hope this helps
  #3 (permalink)  
Old 01-07-2008
gus2000 gus2000 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 157
When you run a script, it executes in a subshell. That subshell has its own environment space, so things like $PWD (or any set variable) will be lost. To paraphrase: "What happens in a subshell stays in a subshell."

Therefore, you canot use a script to change the current working directory of your login shell. You could define an alias, or a function, which would run in the current shell. But the script can't do it.
  #4 (permalink)  
Old 01-07-2008
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Alternatively "source" the script by running with the "." operator, eg period-space-scriptpath

Code:
. scriptpath
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 06:31 AM.


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