LinuxQuestions.org
Visit Jeremy's Blog.
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-30-2006, 05:16 PM   #1
ForumJoiner
LQ Newbie
 
Registered: Nov 2006
Posts: 5

Rep: Reputation: 0
Why doesn't the script change PS1? (RedHat)


Why doesn't the following script work correctly?
The file is called test.sh, and it's in folder /test (so it's /test/test.sh)
I ran chmod +x test.sh.
The script clears the screen, but it doesn't change the PS1, nor the current folder.


I'm using:
Red Hat Release 5.0 (Hurricanne)
Kernel 2.0.32
GNU bash, version 1.14.7(1)


Code:
#! /bin/bash
PS1="\w>"          
cd "/etc"        
clear
Thank you!
 
Old 11-30-2006, 05:24 PM   #2
1337_penguin
Member
 
Registered: Jul 2005
Location: Brighton, UK
Distribution: Mainly Debian and Mepis, but also Slackware, Arch and Mandriva
Posts: 73

Rep: Reputation: 15
Hi

Firstly, there shouldn't be a space between on the first line and also after assigning PS1 you need to do "export PS1" (or you can do it one one line: export PS1="\w> "

That should work.

Hope this helps.

1337_penguin
 
Old 12-01-2006, 12:27 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,353

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Don't forget you have to use
. scriptname
or
source scriptname
otherwise it'll start a subshell and any changes will disappear when script terminates.
 
Old 12-01-2006, 03:59 AM   #4
ForumJoiner
LQ Newbie
 
Registered: Nov 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by chrism01
Don't forget you have to use
. scriptname
or
source scriptname
otherwise it'll start a subshell and any changes will disappear when script terminates.
I didn't forget. I simply didn't know about it :-)
I made an alias "test=source /test/test.sh" and everything works perfect without changing a letter in test.sh.
Thank you so much for this tip.
By the way, it's not very clear for me when I should use "export". In my case, the PS1 changed simply by setting it, without exporting.
Is there a "default exporting" enabled somewhere?
 
  


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
howto change $PS1 when using su (without dash) remcovr Red Hat 2 09-07-2006 12:20 PM
changing PS1 with a script walterbyrd Linux - General 3 02-05-2006 01:09 PM
Change batch script to shell script alan.belizario Programming 5 03-31-2005 12:41 AM
Change batch script to shell script alan.belizario Linux - Software 1 03-30-2005 01:49 AM
PS1 variable wogga Red Hat 2 05-26-2004 05:39 PM

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

All times are GMT -5. The time now is 11:35 PM.

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