LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash script CD question (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-cd-question-767037/)

olan 11-05-2009 06:27 AM

Bash script CD question
 
Hi,

(my first bash script and new to linux)

I need a bash script which will do the following:

Set the currect directory
Run a program.

The reason is that the program then uses the currect directory to locate the files it needs.

I can execute the script but the cd command does not work, google did not realy help.
I have set the path to the script file in my .profile so I just type the name of the script file in bash and it executes ok. that is when I'm at the moment. Any help would be much appreciated. Please use laymans terms in any reply :-)

Thanks O

repo 11-05-2009 06:38 AM

Welcome to LQ
Could you post the script you have ?

catkin 11-05-2009 07:05 AM

As repo wrote, it would help a lot if we could see the script.

Meanwhile
Quote:

Originally Posted by olan (Post 3745569)
I can execute the script but the cd command does not work ...

How do you know the cd command does not work? What happens if you add a line to the script after the cd command to show your current directory? The pwd command would do that.

pixellany 11-05-2009 07:26 AM

Quote:

Please use laymans terms in any reply :-)
If you are learning BASH scripting, it is not going to be in layman's terms----sorry.

This appears to be homework---Regardless, you need to tell us more about the context, show your work so far, and also tell us what books or reference material you are using.

David1357 11-05-2009 07:32 AM

Quote:

Originally Posted by olan (Post 3745569)
I need a bash script which will do the following:

Set the current directory
Run a program

Assuming you have a script like this
Code:

#!/bin/bash
cd /path/to/program
program

You will have to "source" it using either the "source" command or the "." shortcut:
Code:

$ . cd_and_run_program.sh
This assumes that you have to stay in the program directory while the program runs. Otherwise, I am not sure what your problem is.

onebuck 11-05-2009 07:36 AM

Hi,

Welcome to LQ!

So you've shown us your need! What's your deed?

A few links to aid you in the future;

Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Utimate Linux Newbie Guide
LinuxSelfHelp
Getting Started with Linux
Advanced Bash-Scripting Guide

These links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!

:hattip:

olan 11-06-2009 02:57 AM

Thanks
 
Hi,

Thanks for all the replies. As it turns out the issue was caused by the "Windows" line brake after the bash directive !!

Once I converted it to unix the script ran as expected.

Thanks again to everyone.

O


All times are GMT -5. The time now is 09:30 PM.