If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Use of cd in script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-06-04, 00:28
kmrs kmrs is offline
Registered User
 
Join Date: Oct 2004
Posts: 7
Arrow Use of cd in script

Hi Friends,

I am tring to use cd command in the Unix script.
When this command in executing
cd $Archive_Name
It is not changing the directory instead it is telling
"cd: bad substitution"

Then i tried using
"cd $Archive_Name 1>&2"
now it is telling
"bad file unit number"

Can any one help me how to use cd command in the script.

- kmrs

Last edited by kmrs; 12-06-04 at 00:34.
Reply With Quote
  #2 (permalink)  
Old 12-06-04, 07:55
Menasco Menasco is offline
Registered User
 
Join Date: Dec 2004
Posts: 3
Can you tell us what is in the $Archive_Name variable?

Also, set -x is very usefull in troubleshooting scripts.


Billy Menasco
Reply With Quote
  #3 (permalink)  
Old 12-07-04, 04:26
kmrs kmrs is offline
Registered User
 
Join Date: Oct 2004
Posts: 7
Question

Hi Billy Menasco,

Thank you for your reply.

The variable $Archive_Name has the directory to which it has to be changed.

What is the use of set -x?

I am not aware of that,can you explain how to use it.

- kmrs
Reply With Quote
  #4 (permalink)  
Old 12-07-04, 07:35
Menasco Menasco is offline
Registered User
 
Join Date: Dec 2004
Posts: 3
Quote:
Originally Posted by kmrs
The variable $Archive_Name has the directory to which it has to be changed.

What is the use of set -x?
When added to the top of your script "set -x" enables tracing to allow you to monitor what is being executed inside your script.

For more information try this Google Search for set and tracing.


Billy Menasco
Reply With Quote
  #5 (permalink)  
Old 12-07-04, 08:53
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Wink

menasco is correct, "cd: bad substitution" means your $Archive_Name variable is not set
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #6 (permalink)  
Old 12-07-04, 21:33
kmrs kmrs is offline
Registered User
 
Join Date: Oct 2004
Posts: 7
Hi,

I also tried by giving the itself like

cd /kmrs/mydir/Test

Now also I got the error and the command was not executed.

Is there any other way of using the cd command in the script.

Please let me now.

- kmrs
Reply With Quote
  #7 (permalink)  
Old 12-08-04, 04:29
srsjc srsjc is offline
Registered User
 
Join Date: Jun 2004
Posts: 20
Ensure that the directory "/kmrs/mydir/Test" exists.


####### start of script file mycd.sh ####
Archive_Name=/kmrs/mydir/Test
cd $Archive_Name
####### End of script file mycd.sh ####

Execute as follows
. ./mycd.sh


HTH
Reply With Quote
  #8 (permalink)  
Old 12-08-04, 07:25
Menasco Menasco is offline
Registered User
 
Join Date: Dec 2004
Posts: 3
Like srsjc said, sounds like the directory does not exist. You can have the script test to make sure the directory exists. See below.

Code:
Archive_Name=/kmrs/mydir/Test
 
if [ -d $Archive_Name ]
then
$Archive_Name
else
echo "$Archive_name does not exist"
fi
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On