LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-04-2007, 04:48 AM   #1
cdcshu
Member
 
Registered: Jul 2006
Location: Shanghai
Distribution: Fedora, OpenSUSE
Posts: 31

Rep: Reputation: 16
Wink How to make script cmd valid as execut it directly?


Hello,

In my script - sm, I wrote:

++++++++++++++++++++++++++++++++++++++++++++
# !/bin/bash

export CVSROOT=server:cdcshu@xxx:/cvsroot
cvs login
+++++++++++++++++++++++++++++++++++++++++++++

Sure, it worked fine as CVS login operation.

However, this script CVSROOT not valid for normal cvs operation. I must type

export CVSROOT=server:cdcshu@xxx:/cvsroot

again to let CVS remember CVSROOT.

How to make a script executing just like do it directly?

Many thanks,

cdcshu
 
Old 06-04-2007, 05:26 AM   #2
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
http://linuxgazette.net/issue53/eyler.html
... take a look at a comprehensive way to do this.

however, the script should be fine.

Try

gedit setcvs
--------------------------
# !/bin/bash

export CVSROOT=server:cdcshu@xxx:/cvsroot
--------------------------
(save and exit)

chmod +x setcvs
./setcvs
echo $CVSROOT

show the output.

Last edited by Simon Bridge; 06-04-2007 at 06:57 AM.
 
Old 06-04-2007, 05:48 AM   #3
cdcshu
Member
 
Registered: Jul 2006
Location: Shanghai
Distribution: Fedora, OpenSUSE
Posts: 31

Original Poster
Rep: Reputation: 16
Hello simon,

Thanks for this quick reply.

I tried your suggestion - not finishing the reading yet.

On OpenSuse 10.2,

The first time, it did work as your demo. However, once I need to change CVSROOT via the script. It didn't work anymore. i.e. It can only be valid one time.

it-0010773:/home/sam # echo $CVSROOT
CVSROOT=server:sam@192.168.57.65:/cvsroot
it-0010773:/home/sam # export CVSROOT=123
it-0010773:/home/sam # echo $CVSROOT
123
it-0010773:/home/sam # cat setcvs
# !/bin/bash

export CVSROOT=server:sam@192.168.57.65:/cvsroot
it-0010773:/home/sam # ./setcvs
it-0010773:/home/sam # echo $CVSROOT
123
it-0010773:/home/sam #

On Fedora Core 3, setcvs script cannot be valid for next cvs operation. I MUST manually export CVSROOT.

Well, I will read more to figure it out.

Thanks,

cdcshu

Last edited by cdcshu; 06-04-2007 at 05:51 AM.
 
Old 06-04-2007, 05:50 AM   #4
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 757

Rep: Reputation: 145Reputation: 145
Any environment variable that you set in a executable shell script will go away when the script exits because the script gets it's own process and environment which is thrown away when it's done.

One solution is to source it in the current shell process instead of executing it in it's own process. You do that with a leading period like this (you may need to specify the path). Be sure to leave a space after the period:
. sm

Otherwise, you can put the environment variable in your ~/.profile, ~/.bash_profile, or ~/.bashrc file as appropriate. That way it would always be set.

BTW, do you see those obnoxious smiley faces? You can avoid them by clicking Disable smilies in text under Additional Options below the edit window.
 
Old 06-05-2007, 12:42 AM   #5
cdcshu
Member
 
Registered: Jul 2006
Location: Shanghai
Distribution: Fedora, OpenSUSE
Posts: 31

Original Poster
Rep: Reputation: 16
Smile Aaha, that is it:-)

Hello KenJackson,

Thanks so much. Your first solution is what I want. Sure, it did work as my expection on both FC and OpenSuse.

Just type
# . setcvs
# cvs co my-test

No need to manually type

#export CVSROOT=:pserver:cdshu@xxx:/cvsroot

This time should no smile face at :p

BTW, where did you get it from? It made me puzzled a long long time...

Thanks again,

cdcshu
 
Old 06-05-2007, 05:58 AM   #6
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 757

Rep: Reputation: 145Reputation: 145
Quote:
Originally Posted by cdcshu
BTW, where did you get it from? It made me puzzled a long long time...
Back when I was learning bash, I read the O'Reilly book Learning the bash shell, by Newham & Rosenblatt. But you can also find it in Bourne Shell Builtins section of the Bash online manual.

The bash shell is loaded with all kinds of goodies. I continue to learn how to do clever things with it. It puzzles me to realize how many people reject the power of the command-line.
 
  


Reply



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
script or cmd to retun my ip address.... Scrag Linux - Networking 5 07-05-2009 10:19 PM
make[1]: Warning: File `.vmlinux.cmd' has modification time 9.3e+03 s in the future ? Ellops Slackware 2 04-11-2007 04:25 PM
Simple script to copy files, getting \r's at end of cmd ElricM Linux - Newbie 2 07-23-2005 11:21 AM
how to let mozilla execut javascript??? gk_linux Linux - Software 2 11-23-2003 08:32 PM
How can you make valid mdk9.2 rpms from the source? kvtournh Mandriva 1 11-18-2003 11:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:21 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