# cd to sub-folder on Flash using Script



## iic2 (Apr 6, 2009)

Hello,

I'm new to freeBSD ... After two weeks of googling the world to learn (how-to and why nots) freeBSD now installed.  The best tips I got was to backup configuration files. I was having a BALL :e 

I manage to write a few basic script for moving around the system and now I am stuck.  I am trying to cd from /root/bin to a sub-folder on my flash drive and all I get is an image of all the files in sub-folder never while never leaving the root bin. Could someone show me what i'm doing wrong?

#! /bin/sh
	cd /flash
	cd bsd_backup
	cd bsd_conf
   ls

Thanks in advance


----------



## gelraen (Apr 6, 2009)

When you run it like "./script" - child process /bin/sh created and it executes script. So it changes directory only for itself, not for parent process. But if you run it like "source ./script" - then it will be executed by your current shell (if it's sh-compatible) and directory will be changed as you expected.


----------



## lme@ (Apr 6, 2009)

why don't you just use

```
ls /flash/bsd_backup/bsd_conf
```


----------



## DutchDaemon (Apr 6, 2009)

That's way too efficient! There are plenty of people who will happily type


```
cd /var
cd db
cd ports
cd apache
cat options | more
```

And they look quite happy. Oblivious, even.


----------



## vermaden (Apr 6, 2009)

Try that:


```
#! /bin/sh
cd flash/bsd_backup/bsd_conf
ls
```


----------



## iic2 (Apr 6, 2009)

I forgot to mention I'm running freeBSD 7.1 stable using default shell and ee.  My scripts are design to delete, copy and open files.  "Chmod 700 uhistory" - "rehash" They all fire-up like this "uhistory" with nothing else needed.  But it don't work for my "GoTo_b" script posted above.  cd to top-level folder works fine.  cd into it sub-folder, difficult and nothing on the net about it.

gelraen, after such a excellent explanation i'm embarrass.  What do I write in the place of source ???  "source ./_GoTo_b"

lme@, didn't know ls could replace cd and list the files too from that order.  But still I take from your suggestion that what I am trying to do may not be possible or is unknown.  Is this correct?  If so, at lease you provided the  next best thing 

DutchDaemon, Type ee (space) double click to select script, left click to paste and Walla.  My guest; on any job it's their way or no way.  Most *UNIX* people have worked in the industry so long they turn it into fun and competition.

vermaden, that was the very first sequence I tried and it still only re-open the bin that it is called from. Now I wonder is it all about which version is in use or what shell is running.

I appreciate the help


----------



## gelraen (Apr 7, 2009)

Sorry, "source" command available only in bash. In sh this can be done like ". /path/to/script"

Small example:

```
$ cat ./whereami
#!/bin/sh
hostname
$ . ./whereami
imax
```

And for this you don't need execution privilege on script, just reading will be enough.


----------



## iic2 (Apr 7, 2009)

Thanks gelraen, I still don't understand. I am truly a newbee.  But your code tells me it's time to hit the docs   I just need to know if these are the right ones.

For now i'm reading *Practical rc.d scripting in BSD*: http://www.freebsd.org/doc/en_US.ISO8859-1/articles/rc-scripting/

Than I'm going to study PERL. PERL is king right or has it been replaced?
Do I have to study BASH too 

Hope I can be an productive member someday.  I'll stay tune for any advice and I'll say now:

Thanks Everybody


----------



## SirDice (Apr 7, 2009)

Perl is still the Swiss army chainsaw 

Lots of people are using python though, just use what you're most comfortable with.


----------

