LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Scripting fun! (https://www.linuxquestions.org/questions/linux-newbie-8/scripting-fun-411416/)

ceaseless 02-03-2006 08:37 PM

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?

ceaseless 02-03-2006 08:38 PM

Oops, 4. which *shell* is running

frob23 02-03-2006 08:49 PM

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.

sundialsvcs 02-03-2006 08:57 PM

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.

sundialsvcs 02-03-2006 08:58 PM

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.

Penguin of Wonder 02-03-2006 09:02 PM

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.

ceaseless 02-03-2006 09:07 PM

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.

ceaseless 02-03-2006 09:27 PM

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?

mijohnst 02-03-2006 09:42 PM

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. :)

frob23 02-03-2006 09:46 PM

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.

ceaseless 02-03-2006 09:58 PM

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.

frob23 02-03-2006 10:01 PM

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.

ceaseless 02-03-2006 10:20 PM

[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

ceaseless 02-03-2006 10:25 PM

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.

ceaseless 02-03-2006 10:30 PM

# 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!
#---------------------------------------------------------------------


All times are GMT -5. The time now is 09:22 AM.