From bash to csh and zsh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting From bash to csh and zsh
# 1  
Old 09-10-2007
From bash to csh and zsh

... Am I glad to find this forum (and vBulletin too, nice!)..

OK, here's my issue. I have been handballed a bash script, not pretty but functional. I need to change to csh and zsh. For the csh I have the basics (e.g., such as change if/fi to if/endif, quote the variables, and bracket commands). For zsh (ahem), I have no idea and googling for resources hasn't been helpful.

So rather than bash (pun not intended) my head against a screen I decided to see if anyone here is more familiar with this fairly simple conversion process..

Anyway here's the bash.. I need csh and zsh to do the same:

Code:
#!/bin/bash
if echo $HOSTNAME | egrep -q '^somebox0' ; then
        if [ ! $PUBLIC_ENVIRONMENT ];
                then if [ $USER != "root" ];
                        then if grep -sq $USER /usr/local/etc/localusers.$HOSTNAME ;
                                then echo ' *** Interactive access permitted - be nice to others!'
                        else
                                echo ' *** Interactive logins are not permitted on this machine - use PUBLIC instead!'
                                exec /bin/false
                        fi;
                fi;
        fi;
fi;

# 2  
Old 09-10-2007
Quote:
Originally Posted by lev_lafayette
Anyway here's the bash.. I need csh and zsh to do the same:
Out of interest, why?

If you stick to "sh" basics then both ZSH and BASH can run it.

Also systems with csh normally have sh anyway. It sounds like an exercise in generating work and then making more things to maintain. Stick to one common version that works with sh and you will save yourself effort in the long run.
# 3  
Old 09-10-2007
Quote:
Originally Posted by porter
Out of interest, why?
Because some users (boffins) want it. More than one person will use this script, and some are pretty tied to their preferred shell, and ne'er reason nor rhyme will convince them otherwise.

I thoroughly agree with you btw (script in sh, whenever possible), but that doesn't help for the people whom I work for!
# 4  
Old 09-10-2007
Quote:
Originally Posted by lev_lafayette
More than one person will use this script, and some are pretty tied to their preferred shell, and ne'er reason nor rhyme will convince them otherwise.
The shell that a script uses is irrelevant to the person calling it. That is the purpose of the "#!/bin/sh" or similar at the start. This is in the same manner that you don't care if a compiled program is written in C, C++, Pascal or raw assembler.

What you will end up with is a nightmare for maintaining the script as you will have three separate versions.
# 5  
Old 09-10-2007
Quote:
Originally Posted by porter
The shell that a script uses is irrelevant to the person calling it.
Not in this case.

Quote:
What you will end up with is a nightmare for maintaining the script as you will have three separate versions.
Which is what I requested in the first post.
# 6  
Old 09-10-2007
Write one script and then have

Code:
#!/bin/csh
commonScript

Code:
#!/bin/bash
commonScript

Code:
#!/bin/sh
commonScript

Code:
#!/bin/zsh
commonScript

# 7  
Old 09-10-2007
Quote:
Originally Posted by porter
Write one script and then have
Smilie

You know that doesn't work. bash/sh use if/fi constructs whilst csh uses if/endif for starters. As I said in the first post Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

MacOS 10.15 (Catalina) switches from bash to zsh

Interestingly Apple has decided to switch the default shell for new users from bash to zsh in MacOS Catalina (10.15) Use zsh as the default shell on your Mac - Apple Support Another interesting fact is that Catalina also comes with /bin/dash (5 Replies)
Discussion started by: Scrutinizer
5 Replies

2. Shell Programming and Scripting

Run bash command inside zsh script

Hi, I would like to run following code in bash inside a zsh script. (In this case is output unfortunately very different if you run it in zsh). I tried to put "bash" in front of the code but I obtained following error message "bash: do: No such file or directory " eve though I merged the whole... (7 Replies)
Discussion started by: kamcamonty
7 Replies

3. Shell Programming and Scripting

Changing script from csh to bash

Hello Guys I have a script working fine on csh, but I would like to change it to bash, how I should change this command to be able to work as bash script. :wall: if ( $fsw > "0" ) then foreach swath ( `awk 'BEGIN {for (i='$fsw';i<='$lsw';i++) printf ("%s\n", i) }'` ) ## work to be done... (2 Replies)
Discussion started by: jiam912
2 Replies

4. Shell Programming and Scripting

a simple for loop in bash and zsh

Hi! I am just starting to learn scripting. I am trying a simple script in bash and zsh I have two questions: First: Why zsh does not expand the var M? What I am doing wrong? localhost galanom # bash -c 'M="m1 m2 m3 m4 m5"; for x in $M; do echo "<$x>"; done' <m1> <m2> <m3> <m4> <m5>... (1 Reply)
Discussion started by: galanom
1 Replies

5. UNIX for Dummies Questions & Answers

Running CSh scripts in Bash

Hi, I have some csh scripts and I want to run them in .bashrc. I use these techniques without any success: . test.csh or csh test.csh The first one assumed that the scripts is a bash script, so showed me errors. The second one finished without giving proper result. Can anybody offer... (6 Replies)
Discussion started by: mjdousti
6 Replies

6. Shell Programming and Scripting

Bash one liner to CSH

Hello all, I have a Bash command I'm using on one system that replaces text in filenames, I'ts not working on another system that uses the Csh shell. Can anyone tell me what I need to do when i run for f in *;do mv $f ${f/text1/text2};done on the CSH shell i get ""Missing }."" (7 Replies)
Discussion started by: mike171562
7 Replies

7. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

8. Shell Programming and Scripting

different shell csh bash

I'm always having to work in the cshell, but occasionally want to run a command using bash. is that possible? I know I could write a shell script and call bash at the begining with #!/usr/bin/bash and then my command, is there another way? (1 Reply)
Discussion started by: ajp7701
1 Replies

9. Shell Programming and Scripting

Converting bash script to csh

Hi, I'm a beginner in scripting and I recently wrote a bash script that would've worked fine until I realized it needed to be written in csh. Could someone please show me how to correctly change the syntax from bash to csh in this script? Any help will be greatly appreciated. I can provide more... (4 Replies)
Discussion started by: Kweekwom
4 Replies

10. Solaris

Missing init files for zsh and bash

I change my default shell to zsh but can't find the init files, .zshrc and .zlogin from /export/home and /home. The other shells init files are there:.cshrc, .profile and .login. Am I suppose to use these as templates? Also, bash_history is there but not zsh_history although zsh do keep a... (2 Replies)
Discussion started by: maag
2 Replies
Login or Register to Ask a Question