![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. |
|
||||
|
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 |
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|