Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cd command in scripts? 1

Status
Not open for further replies.

hornetbloke

Technical User
Aug 12, 2002
26
0
0
NL
Got a strange one on a Solaris 6 machine. As part of the script I want to cd into a directory and tar the contents without the / and directory name in front of it.
I'm using the absolute pathname of the cd command but for some reason it just doesn't work. I put echo `pwd` straight after it and I can see from that that it isnb't working.
Has anyone come across this problem before?
Or is there another way of tarring the contents of a directory without including the /<dir name>?
 
Can you post the relevant lines of your script?

On the tar command line, how are you specifying which files and/or directories to archive? Annihilannic.
 
Just use cd rather than /usr/bin/cd.

Don't know why, but that seems to work. HTH.
 
That certainly did the trick. Never seen it before but I'll remember it for future use. Thanks a lot for the help guys, that was really bugging me.
 
Probably because it is a shell builtin rather than a seperate command in /usr/bin. If you type in &quot;type cd&quot; you should get the response that it is shell builtin so telling it to go to /usr/bin would be incorrect.
 
Yup, it's because cd is a shell built-in command. Just putting cd will cause the process the shell's running in to change to that default directory.

When you put /usr/bin/cd, that will run the /usr/bin/cd executable in a spawned subprocess. The SUBPROCESS forks, executes the cd correctly, then exits and returns control to the process your script is running in, which still has the same default directory as before.

Just keep im mind that every external command and script runs as a separate sub-process. Unless you source it (&quot;. myscript&quot;).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top