Moving from .cshrc to .bashrc


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Moving from .cshrc to .bashrc
# 1  
Old 08-14-2011
Moving from .cshrc to .bashrc

At work I've been moved from ksh to bash per our policy. I haven't configured a .profile or .cshrc before but when I first started the guy that trained me (on just what I need to know in order to do the job) let me copy his .profile, .cshrc, and .cshrc_aliases file so we could all use them and then upload them to each server on which we administer accounts. We've always used ksh as a default so I'm not sure why he had us put a .cshrc file as I believe this pertains to c shell but when i would edit this file it would definitely reflect the change so I just rolled with it.

Now I have to use bash and I just want to get a few tweaks implemented from .cshrc but the syntax appears wrong. For example, in my .cshrc I have one of many if/then statements:
Code:
echo $host
if ( $host == 'a.a.a.a.') then
setenv env 'development';

if ( $host == 'b.b.b.b') then
setenv env 'production';

where a.a.a.a and b.b.b.b represent hostnames in our company. I want to login to a devlopment, production, or other environment server and have my prompt reflect that I am in the respective environment. I noticed that in .cshrc the setenv seems to be the equivalent of export in .bashrc but I tried replacing all %s/setenv/export/g and I still received an error when sourcing my .bashrc:
Code:
-bash: export: `1': not a valid identifier
-bash: export: `.:<company_defined_paths_omitted>:/usr/local/bin:/usr/bin:/usr/sbin:/bin:': not a valid identifier
-bash: export: `a.a.a.a': not a valid identifier
-bash: export: `': not a valid identifier

-bash: .bashrc: line 55: syntax error: unexpected end of file

Again - a.a.a.a is a hostname in our company. Is there more to defining those aliases or am I using the export directive incorrectly?
# 2  
Old 08-14-2011
post your .bashrc here
# 3  
Old 08-14-2011
bash is not csh. There is not a search-replace that will make csh code be bash code. You'll have to rewrite it.

Code:
case "$HOST" in
host1)
        export stuff;
        ;;
host2)
        export otherstuff;
        ;;
*)     echo "unknown host"
        ;;
esac

# 4  
Old 08-15-2011
Quote:
Originally Posted by h@foorsa.biz
post your .bashrc here
I can't do it verbatim but I've edited the parts specific to my company:
Code:
#
# Profile
#
export POSIXLY_CORRECT 1
export PATH     '.:<path_removed>:/usr/local/bin:/usr/bin:/usr/sbin:/bin:'

export host `uname -n`
export env '';
echo $host
if ( $host == 'a.a.a.a.') then
        export env 'dev'
        export host_group 'dev_environment:';
else if ( $host == 'b.b.b.b.') then
        export env 'qa'
        export host_group 'qa_environment:';
endif

#if( -e .bashrc_aliases) then
#    source .cshrc_aliases
#endif

set prompt = "[%n@$env %~]"

Granted - this was all copied from my .cshrc file and the term "export" was replaced by "setenv". I haven't tried the aforementioned edit yet - not so sure the part: host) looks right with an open parenthesis but I'll try it later.
# 5  
Old 08-15-2011
It's not just the export vs setenv that's different. The entire language is different. bash is not csh. You'll have to rewrite it as bash code. The example I posted for you would be a good start.

Last edited by Corona688; 08-15-2011 at 05:30 PM..
# 6  
Old 08-20-2011
Quote:
Originally Posted by Corona688
It's not just the export vs setenv that's different. The entire language is different. bash is not csh. You'll have to rewrite it as bash code. The example I posted for you would be a good start.
Corona thanks for your suggestion. As I stated earlier I pasted the contents of the find/replace without entering your edits yet as I have to continue my work as usual before I can test new configurations and I've been extremely busy.

Now, that being said I tried implementing what you suggested and I'm having a problem. I'm just trying to get SOMETHING working for starters so I'm trying this snippet in my .bashrc:
Code:
export $HOST `uname -n`
echo $HOST

case $HOST in
"a")
        export $env="dev";
        ;;
"b")
        export $env="prod";
        ;;
esac

where "a" and "b" are hostnames of servers in my company. Then I run source .bashrc and I keep getting an error message stating:
Code:
-bash: export: `a.a.a.a': not a valid identifier

where a.a.a.a is the fqdn of the host I'm using. Why is this happening?
# 7  
Old 08-22-2011
export makes the NAME of your variable available to child processes. A variable has a NAME and a VALUE assigned with the EQUAL SIGN (=) in the form: name=value. An example in the bashrc that you posted should be->
Code:
POSIXLY_CORRECT=1
export POSIXLY_CORRECT
#which could be written as
export POSIXLY_CORRECT=1

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

CSHRC and PATH problem please help

I'm doing some IVR programming and it uses Solaris 10. I know little about Unix, or CSH, but I think it's a problem with my .cshrc file. I was getting an error: "nstancehomedir/sqllib/bin/db2fupdt: Command not found" and also "set: Syntax error" when I log in. I found db2fupdt in 2 directories,... (2 Replies)
Discussion started by: jstevanus
2 Replies

2. Solaris

Explain @(#)cshrc 1.11 89/11/29 SMI

What does ' @(#)cshrc 1.11 89/11/29 SMI ' mean? Can someone please deconstruct and explain the parts? # @(#)cshrc 1.11 89/11/29 SMIIt is at the top of a the .cshrc of a new Solaris account I am working on. I am familiar with using the first line of a script for setting the program/shell to... (2 Replies)
Discussion started by: fgrirx
2 Replies

3. Shell Programming and Scripting

Problem with my .cshrc

Hello everyone, I write a ~/.cshrc for set class path to run my java application. The file is listed below. setenv YFILTER_HOME ~/yfilter-2.0 setenv PATH "$YFILTER_HOME/bin:$PATH" setenv CLASSPATH... (1 Reply)
Discussion started by: perl0101
1 Replies

4. Virtualization and Cloud Computing

.cshrc file

Hi All, I was hoping someone could help me with the following query I have please in relation to NX Nomachine. Is there a way to get my .cshrc file in say my “US” home dir” to run when I login to another server e.g say a UK server? Any advise would be much appreciated, thanks (3 Replies)
Discussion started by: zainster
3 Replies

5. UNIX for Dummies Questions & Answers

flags inside .cshrc

Hi, I use a specific utility in my .cshrc for setting up the right fonts and I believe it's sufficient to run it once for a whole session. Since I have sourced it in my .cshrc, it runs every time I do a source of .cshrc or invoke every new terminal. To resolve this issue, I thought of... (1 Reply)
Discussion started by: oldtrash
1 Replies

6. UNIX for Dummies Questions & Answers

doubt in .cshrc

what kind of information is there .cshrc ? I want to set an alias in the form of =>#alias setprompt 'set prompt=">>$user<<@`hostname`:${cwd}% "' Ex. alias pr 'cd /home/username' when I make the change and try to do $pr ... its saying pr: command not found Is there any way I can... (0 Replies)
Discussion started by: priyam
0 Replies

7. UNIX for Dummies Questions & Answers

.cshrc flie help

How can I set up my .cshrc file to do as the posix shell does the escape+k to scroll my command history Thanks Oh BTW, Hi I'm new to the forum. (2 Replies)
Discussion started by: Lefty
2 Replies

8. UNIX for Advanced & Expert Users

.cshrc and .login overwritten !!

Hi, My account is : abcd I belong to a group: pqrs Some thing straneg happened yesterday. My .cshrc and .login got overwritten into pqrs's .cshrc and .login I obviously did not explicitly overwrite pqrs's .cshrc. Are there any reasons how this could have happened indirectly due to... (5 Replies)
Discussion started by: gjthomas
5 Replies

9. UNIX for Dummies Questions & Answers

how to specify header directory in .cshrc

in my .cshrc file, i can set my library files directory like this : setenv LD_LIBRARY_PATH "/usr/openwin/lib" now i want to specify my header files directory. please teach how to set it and what/how is the syntax thank u (1 Reply)
Discussion started by: champion
1 Replies

10. Shell Programming and Scripting

cshrc

where are my .cshrc files ? (4 Replies)
Discussion started by: cubicle^dweller
4 Replies
Login or Register to Ask a Question