LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-05-2009, 06:27 AM   #1
olan
LQ Newbie
 
Registered: Nov 2009
Posts: 2

Rep: Reputation: Disabled
Question 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
 
Old 11-05-2009, 06:38 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Welcome to LQ
Could you post the script you have ?
 
Old 11-05-2009, 07:05 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

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

Meanwhile
Quote:
Originally Posted by olan View Post
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.
 
Old 11-05-2009, 07:26 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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.
 
Old 11-05-2009, 07:32 AM   #5
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by olan View Post
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.

Last edited by David1357; 11-05-2009 at 07:34 AM. Reason: Added assumption about behavior.
 
Old 11-05-2009, 07:36 AM   #6
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,923
Blog Entries: 44

Rep: Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158
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!

 
Old 11-06-2009, 02:57 AM   #7
olan
LQ Newbie
 
Registered: Nov 2009
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thumbs up 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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Script Question nade Programming 2 05-22-2009 09:36 PM
bash script question edward_scott Linux - Newbie 4 08-26-2006 02:54 PM
Bash script question deiussum Programming 6 08-14-2004 11:43 AM
bash script question djgerbavore Linux - Newbie 3 07-08-2004 03:39 PM
A bash script question J_Szucs Programming 2 05-13-2003 02:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration