LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 02-03-2006, 08:37 PM   #1
ceaseless
LQ Newbie
 
Registered: Jan 2006
Posts: 24

Rep: Reputation: 15
Scripting fun!


O.K., I know there are several scripting langauges or shells out there, the two most prevailant seem to be bash and csh. I several questions about these two in particular.

1. Is there a link or source which does a quick, side by side comparison of these two?

2. What controls which shell becomes the default? Is it in .login? I boot to Gnome and use terminal to get a command prompt.

3. If you're running bash, then 'source" is needed to run a csh script, correct?

4. Is there a command which tells you which script is currently running?

5. Should it matter which shell is running if all my scripts have the !#/bin/bash or !#/bin/csh as their first line?
 
Old 02-03-2006, 08:38 PM   #2
ceaseless
LQ Newbie
 
Registered: Jan 2006
Posts: 24

Original Poster
Rep: Reputation: 15
Oops, 4. which *shell* is running
 
Old 02-03-2006, 08:49 PM   #3
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: OpenBSD, Debian, FreeBSD
Posts: 1,450

Rep: Reputation: 48
1) There are many online discussions -- the most common Csh Programming Considered Harmful. Which is a decent discussion on why using csh for programming is generally a bad idea. Note, I prefer tcsh as my main method of interaction but rarely use it for scripts unless the script is very basic and not going to leave my control.

2) /etc/passwd determines the default shell.

3) I have no idea what you're asking.

4) echo $SHELL; should tell you the current shell... this is not true in reality often enough to make me uncomfortable even suggesting it. Often changing shells does not change this.

5) It should not matter... your regular shell will not play a role as long as the first line points to a valid shell. Note, some systems do not correctly support this and will always use /bin/sh -- no modern system I know of has that limitation. It is also important to note that /bin/bash is not standard and will not work on most *nix operating systems outside linux. /bin/sh will always work but will not always point to bash.

Although it is fine to use bash if you want for your own stuff... it does effect portability and you should consider using plain bourne shell without bash syntax if possible. Just a word of advice from someone who spent a few years passing scripts from *BSD to Linux to Solaris.
 
Old 02-03-2006, 08:57 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,671
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
You know, I just do very little actual Bash-shell scripting. I normally use Python. I know of others who swear by (or swear at) Perl. Still others use PHP for web-sites and also use it for other scripting tasks as well.

You can build entire applications, cross-platform ones at that, with Python tools like "Boa Constructor," which is extremely nice.

It is very nice to be able to "script things," although I find it very painstaking to do it in Bash-scripting. Given the plethora of other, better choices out there, I simply use one of those.

Note: The so-called "shebang" #! that you'll find at the start of any shell-script specifies the command-processor to be used. So you can write a command, and execute it, in any of these languages with no difference in how you invoke them.
 
Old 02-03-2006, 08:58 PM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,671
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
I'd strongly encourage you to spend some time learning or at least looking-at all three of the languages I just mentioned. All of them, most likely, are already present on your computer.

All of them work just fine in Windows, too.
 
Old 02-03-2006, 09:02 PM   #6
Penguin of Wonder
Senior Member
 
Registered: Sep 2005
Location: West Virginia
Distribution: Gentoo
Posts: 1,249

Rep: Reputation: 45
My suggestion is look at all of them, but only really master one. If you do this you'll pick up the other two really easy, if you ever deciede you need the other two.
 
Old 02-03-2006, 09:07 PM   #7
ceaseless
LQ Newbie
 
Registered: Jan 2006
Posts: 24

Original Poster
Rep: Reputation: 15
Those langauges sound great and I will learn them. I am getting into Linux for one reason, to use a specific weather analysis program called GEMPAK. GEMPAK requires that a set-up file called Gemenviron be run and I was given both a bash and csh version of this file.

I wrote scripts which make use of wget to retrieve the weather data for GEMPAK. They all work but I started running into problems putting them into crontab.
 
Old 02-03-2006, 09:27 PM   #8
ceaseless
LQ Newbie
 
Registered: Jan 2006
Posts: 24

Original Poster
Rep: Reputation: 15
Another issue related to my last post: why when I invoke csh would a message pop up saying "(dir name/file): no such file or directory"? Is csh reading a set up file before it runs?
 
Old 02-03-2006, 09:42 PM   #9
mijohnst
Member
 
Registered: Nov 2003
Location: Huntsville, AL
Distribution: RHEL, Solaris, OSX, SuSE
Posts: 419

Rep: Reputation: 31
You sound alot like I was ceaseless. I needed to automate several of the things that I'm working on and with much help from this forum (Thank you all) I've learned quite a bit on scripting with bash. I am currently learning perl and because I have a good understanding of how bash is structured I'm having a much easier time learning it and it's making sense to me. I agree with posts above about learning one well and then trying another.

You've picked the right place for help... There are some amazingly sharp people here.
 
Old 02-03-2006, 09:46 PM   #10
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: OpenBSD, Debian, FreeBSD
Posts: 1,450

Rep: Reputation: 48
Quote:
Originally Posted by ceaseless
Another issue related to my last post: why when I invoke csh would a message pop up saying "(dir name/file): no such file or directory"? Is csh reading a set up file before it runs?
.login and .cshrc get read by csh when it starts.

Is that a literal error? Is this every time or with certain scripts? You can find that and fix it faily simply.
 
Old 02-03-2006, 09:58 PM   #11
ceaseless
LQ Newbie
 
Registered: Jan 2006
Posts: 24

Original Poster
Rep: Reputation: 15
Everytime I type csh, "GEMPAK5.8.4/Gemenviron: No such directory or file" appears which leads me to believe something is incorrctly set in .login or .cshrc.
 
Old 02-03-2006, 10:01 PM   #12
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: OpenBSD, Debian, FreeBSD
Posts: 1,450

Rep: Reputation: 48
Try: `grep GEMPAK ~/.cshrc ~/.login` and see what that turns up. That's probably where our problem is.

Edit, you most likely do not want to remove the line... we want to check it for syntax errors and that it's pointing to a valid location.

Last edited by frob23; 02-03-2006 at 10:03 PM.
 
Old 02-03-2006, 10:20 PM   #13
ceaseless
LQ Newbie
 
Registered: Jan 2006
Posts: 24

Original Poster
Rep: Reputation: 15
[gempak@vortex ~/GEMPAK5.8.4]$ grep GEMPAK ~/.cshrc ~/.login
/home/gempak/.cshrc:source /GEMPAK5.8.4/Gemenviron
grep: /home/gempak/.login: No such file or directory
 
Old 02-03-2006, 10:25 PM   #14
ceaseless
LQ Newbie
 
Registered: Jan 2006
Posts: 24

Original Poster
Rep: Reputation: 15
the only line in .cshrc is: source /GEMPAK5.8.4/Gemenviron

Gemenviron IS in that directory. FYI: Gemenviron set a bunch of path variables needed by GEMPAK.

Last edited by ceaseless; 02-03-2006 at 10:26 PM.
 
Old 02-03-2006, 10:30 PM   #15
ceaseless
LQ Newbie
 
Registered: Jan 2006
Posts: 24

Original Poster
Rep: Reputation: 15
# Gemenviron file for GEMPAK 5.8
#
# Sets environment variables used in running GEMPAK
# UNIDATA Program Center 6/1/92 (PB)
# Revised 8/31/94 for GEMPAK 5.2
# Modified 12/95 for Gempak5.2.1/Nawips (Chiz)
# Modified 8/96 for Gempak5.4/NAWIPS (Chiz)
# Modified 10/00 for Gempak5.6/NAWIPS (Chiz)
# Modified 3/04 for Gempak5.7/NAWIPS (Chiz)
#---------------------------------------------------------------------
# The command
# source Gemenviron
#
# or the individual lines below, must be included in your .login or
# .cshrc file!
#---------------------------------------------------------------------
 
  


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
Just for fun hyper guy Linux - Newbie 4 03-04-2004 06:07 PM
Various Fun wdavidson Linux - General 4 09-29-2003 10:13 AM
More perl scripting fun BertsBackyard Programming 12 01-30-2003 08:54 AM
Just for fun neo77777 General 0 09-24-2002 06:42 PM
Just for FUN! How would you... macdudelx Linux - General 18 08-11-2002 01:34 AM

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

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