Welcome, Guest. Please Login
 
  HomeHelpSearchLogin FAQ Radified Ghost.Classic Ghost.New Bootable CD Blog  
 
Pages: 1 2 3 4
Send Topic Print
UNIX Shell scripting (Read 58892 times)
Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
UNIX Shell scripting
Jun 12th, 2009 at 12:42am
 
Regarding UNIX Shell scripting, I read the following statement, but don't understand exactly what it means. Can any UNIX/Linux studs clarify?

Quote:
The Bourne and C-shell families are completely incompatible from a programming standpoint, and they differ in their implementations of other certain features (such as command history), but otherwise they can be used interchangably.

What can be used interchangably? Shell scripts? I don't see how these two shell families can be "completely incompatibly," but "used interchangably."

I think what it's saying is that the two families of shells behave similarly when used on an interactive basis to start other programs, then they behave similarly. But scriots written for one (programming standpoint) will not work in the other. Yes?
 
WWW  
IP Logged
 

MrMagoo
Übermensch
*****
Offline


Resident Linux Guru

Posts: 1026
Phoenix, AZ (USA)


Back to top
Re: UNIX Shell scripting
Reply #1 - Jun 12th, 2009 at 5:29am
 
I'd need more context to understand the statement.  Can you provide a link?

My guess would be that they are compatible in that you can use either one on almost any Linux system.  Both are compatible with the kernel in the same ways.  In fact, you can have both installed next to each other and switch between them at any time.  What you can't do is write a script in one and expect it to run well in the other.  The format and behavior of the commands are different in important ways.

I'm not sure where you ran across this information or what you are reading up on, but I'd stick to the Bourne Again Shell (BASH).  Bash comes installed as the default shell for every distribution of Linux I know of and many BSD distributions.  The only system I can think of off the top of my head that doesn't come with Bash as default is Solaris, which I think uses csh (C shell), and even then BASH is installed as an option. 

Besides, almost anything you can do in a different shell can be done just as easily in a program written in Perl or Ruby or C, which can then be called by a bash script.  Bash is the only shell I use, and it has never stopped me from doing anything the way I wanted to do it.

I'm not saying the other shells don't have their place.  People who live in the command line can move around with amazing speed using the right shortcuts in the right shell.  I'm just saying that for anyone whose world extends past a shell prompt, your time is best served by learning BASH and then moving on to other tech skills like programing languages.
 
WWW  
IP Logged
 
Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Re: UNIX Shell scripting
Reply #2 - Jun 12th, 2009 at 9:10am
 
MrMagoo wrote on Jun 12th, 2009 at 5:29am:
Can you provide a link?

video tutorial

http://www.vtc.com/products/Unix-Shell-Fundamentals-tutorials.htm

see link titled "which shell"
 
WWW  
IP Logged
 
Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Re: UNIX Shell scripting
Reply #3 - Jun 12th, 2009 at 2:17pm
 
as a little extra info, i ran across this:

http://www.amazon.com/Wicked-Cool-Shell-Scripts-Taylor/dp/1593270127/

.. to a book titled "wicked cool shell scripts", where one of the reviewers says:

Quote:
I also don't think there is anything "wicked cool" about shell scripting in general: if you need anything complex at all, Perl or something else is probably a much better way to to it. Shell scripting gets awfully nasty awfully fast.

However, I was wrong. Yes, shell scripting is an abominable way to approach most of the tasks this book explores. Just the same, the author does it "wicked cool" and you can learn a lot both from how he sees the problem and the other Unix tools he uses as part of the script.
 
WWW  
IP Logged
 
MrMagoo
Übermensch
*****
Offline


Resident Linux Guru

Posts: 1026
Phoenix, AZ (USA)


Back to top
Re: UNIX Shell scripting
Reply #4 - Jun 12th, 2009 at 4:35pm
 
I couldn't get the video to come up.

As far as the book goes, I definitely agree with most of the reviewers that any shell script more than about 15 lines can probably be done better in Perl or something else.  On the other hand, if you learn shell scripting, you'd be learning both shell and getting your feet wet in basic programing at the same time, so it might be good for  you.

My only concern about that book is that it might not provide enough of an explanation about what is going on for you to easily follow.  See this comment in the reviews:

Quote:
Taylor does some neat stuff with shell scripts, but he doesn't spend much time explaining what goes on in them. Each is accompanied by a terse paragraph explaining "how it works", which generally only addresses one particular aspect of the script (ie, POSIX-style "variable slicing"). Shell syntax is terse and many of the reserved keywords and functions are not self-evident. If you don't know, for example, what "${#remainder}" returns, Taylor won't help you; you will have to look it up in a tutorial or a reference work elsewhere.


At a minimum, I think you'd have to supplement this book with some shell scripting tutorials on the web.
 
WWW  
IP Logged
 
Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Re: UNIX Shell scripting
Reply #5 - Jun 12th, 2009 at 5:37pm
 
MrMagoo wrote on Jun 12th, 2009 at 4:35pm:
I think you'd have to supplement this book with some shell scripting tutorials on the web. 

Like this?

http://www.vtc.com/products/Unix-Shell-Scripting-Advanced-tutorials.htm
 
WWW  
IP Logged
 

MrMagoo
Übermensch
*****
Offline


Resident Linux Guru

Posts: 1026
Phoenix, AZ (USA)


Back to top
Re: UNIX Shell scripting
Reply #6 - Jun 12th, 2009 at 6:43pm
 
That's pretty basic stuff.  Great to start with, but you may still need to supplement the lessons in the book with some googling for things you don't understand.
 
WWW  
IP Logged
 
Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Re: UNIX Shell scripting
Reply #7 - Jun 13th, 2009 at 12:47pm
 
MrMagoo wrote on Jun 12th, 2009 at 6:43pm:
That's pretty basic stuff.

Really? It says "Advanced".

Seems that learning the UNIX/Linux shell is really about learning the commands, and what those commands do, and the various switches available to each command .. no?
 
WWW  
IP Logged
 
MrMagoo
Übermensch
*****
Offline


Resident Linux Guru

Posts: 1026
Phoenix, AZ (USA)


Back to top
Re: UNIX Shell scripting
Reply #8 - Jun 13th, 2009 at 3:55pm
 
Ya.  If you understand everything in that course, you will have a very solid understanding of the basics.  It has everything you need for a good foundation.  But to call it 'Advanced' would be overly generous.  I wouldn't hire a Linux Admin who doesn't know at least 80% of that stuff off the top of his head, and he'd have to be at least familiar with the rest.

And ya, like I said in other post, learning the commands is the first half of the battle.  In some ways its the harder half.  That's not to say that it's hard.  I found it very frustrating at first because I knew exactly how to get things done in Windows, but had to research how to do even simple things in Linux.  Once you learn most of the basic commands, tho, your confidence will sky rocket and learning the rest gets a lot easier/faster.

The second half of the battle learning shell is understanding config files, environment variables, input and output, and things like that.  This is stuff you don't need just to get around in the shell, but for the advanced stuff it's essential.

As good as Ubuntu has gotten with automatic setup of things and providing graphical tools for the rest, there are still many things I prefer to do in the command line just because it's easier to get around and quicker to get things done. 

One other thing you will want to learn is the Vi text editor.  It's not very intuitive, but almost every distro comes installed with it, and you'll often have to make quick edits to config files.  I'll see if I can find a good tutorial on it and post it later.  It's pretty powerful once you get comfortable in it.
 
WWW  
IP Logged
 
Rad.in.UbuntuVM
Radmeister
**
Offline


Rad in Ubuntu 9.04 Jaunty
Virtual Machine

Posts: 92


Back to top
Re: UNIX Shell scripting
Reply #9 - Jun 13th, 2009 at 5:53pm
 
MrMagoo wrote on Jun 13th, 2009 at 3:55pm:
But to call it 'Advanced' would be overly generous.

okay.

MrMagoo wrote on Jun 13th, 2009 at 3:55pm:
I wouldn't hire a Linux Admin who doesn't know at least 80% of that stuff off the top of his head,

eyebrow-raising statement

MrMagoo wrote on Jun 13th, 2009 at 3:55pm:
Once you learn most of the basic commands, tho, your confidence will sky rocket and learning the rest gets a lot easier/faster.

i am just beginning to experience this. For example, yesterday i updated the Movable Type blog software (to v4.26) .. which used to intimidate me, for fear of trashing the whole system, when I had to do everything file-by-file. Now I upload the entire archive to the server (quick), uncompress there (quick), and copy new files (overwrite) to their default locations.

All that remains is to click a few buttons saying, Ÿeah, I wanna update the program and database). Accomplished in less than 5 mins .. without even having to concentrate on what I was doing .. tho I *did* go back to notes Iǘe made on the procedure, and reference the commands detailed there, so I wouldnt (< theres that beep again) screw up. But I felt very good about how my skills are developing.

MrMagoo wrote on Jun 13th, 2009 at 3:55pm:
The second half of the battle learning shell is understanding config files, environment variables, input and output, and things like that. 

Dont really know what youŕe (<no beep there, so it only happens in certain instances) talking about there.

MrMagoo wrote on Jun 13th, 2009 at 3:55pm:
As good as Ubuntu has gotten with automatic setup of things and providing graphical tools for the rest, there are still many things I prefer to do in the command line just because it's easier to get around and quicker to get things done.

I witnessed this firsthand when I first got the VPS, and saw the admins there doing EVERYTHING in the command-line, and how EASY it was for them to accomplish these tasks, and how POWERFUL their commands were. The word > awe may be an exaggeration, but not a gross one.

MrMagoo wrote on Jun 13th, 2009 at 3:55pm:
One other thing you will want to learn is the Vi text editor. 

Youǘe (<there the apostrophe turns the v into a capital u, weird) mentioned before. I have this:

http://oreilly.com/catalog/9780596529833/

Amazon reviews look good:

http://www.amazon.com/Learning-Vim-Editors-Arnold-Robbins/dp/059652983X/

What are the other text editors and why do you prefer Vi/Vim? What about ... e-something? (I forget the name.)

RE: Command-line terminology, what do you know about options vs switches? Are they the same thing? Iǘe heard them called both. What is the skinny?
 
WWW  
IP Logged
 
MrMagoo
Übermensch
*****
Offline


Resident Linux Guru

Posts: 1026
Phoenix, AZ (USA)


Back to top
Re: UNIX Shell scripting
Reply #10 - Jun 13th, 2009 at 7:25pm
 
Rad.in.UbuntuVM wrote on Jun 13th, 2009 at 5:53pm:
Dont really know what youŕe talking about there.

Don't worry, you don't need that stuff yet.  You are on the right track.  You can learn that stuff a little at a time, and it will be obvious when you need it.

Rad.in.UbuntuVM wrote on Jun 13th, 2009 at 5:53pm:

Oreilly makes great books.  That one will have MORE than enough information on vi/vim.  My only bit of advice with that book is don't get too bogged down in it.  You probably need less than half the info in that book to use vi/vim effectively.  The rest of the info will be useful, but probably only marginally so at first.  Maybe best to read that book a few chapters at a time.

Rad.in.UbuntuVM wrote on Jun 13th, 2009 at 5:53pm:
What are the other text editors and why do you prefer Vi/Vim? What about ... e-something? (I forget the name.) 

Emacs and Nano are the two most popular substitues for vi.  There are probably hundreds that are less popular.

I think the reason I like Vi so much is because I've used it so much.  It is the default editor on most distributions (almost all Linux, Solaris, and BSD.)  So, I got used to it just because it was there so often.  I actually hated it at first, but once you get used to it, it gets the job done nicely. 

One thing I want to mention is that Vim is the newer version, and I highly prefer Vim.  Vi is much pickier, in my opinion, and doesn't handle the delete key or the arrow keys intuitively.  Many distributions (Red Hat, for sure) come installed with Vim, and alias it to Vi.  So, when you execute "vi somefile" you really end up opening that file in Vim.  I like this behavior. 

Ubuntu doesn't do that.  It ships with Vi only.  If you'd like to try out Vim, which I prefer, "sudo apt-get install vim" will install it.  Then just "vim somefile".

Rad.in.UbuntuVM wrote on Jun 13th, 2009 at 5:53pm:
RE: Command-line terminology, what do you know about options vs switches? Are they the same thing? Iǘe heard them called both. What is the skinny?

Most of the time the words switches, flags, and options all mean the same thing in this context.  Sometimes 'options' refers to settings stored in a config file somewhere rather than typed with every command.

Rad.in.UbuntuVM wrote on Jun 13th, 2009 at 5:53pm:
(Youǘe  <there the apostrophe turns the v into a capital u, weird)

I think your key mappings for your keyboard are set to something international.  Maybe French. 

Click on System->Administration->Languages and make sure it is set to US English.  Check for the same thing in System->Preferences->Keyboard->Layouts
 
WWW  
IP Logged
 

Rad.in.UbuntuVM
Radmeister
**
Offline


Rad in Ubuntu 9.04 Jaunty
Virtual Machine

Posts: 92


Back to top
Re: UNIX Shell scripting
Reply #11 - Jun 13th, 2009 at 7:30pm
 
what does this do?

cd /

i mean, i know cd changes directory., but where does / take you?
 
WWW  
IP Logged
 
MrMagoo
Übermensch
*****
Offline


Resident Linux Guru

Posts: 1026
Phoenix, AZ (USA)


Back to top
Re: UNIX Shell scripting
Reply #12 - Jun 13th, 2009 at 7:51pm
 
Heh.  It takes you to /.  '/' is the root of the file system.  Kinda confusing, I know. 

Also, don't confuse it with '/root', which is not the root directory, but the root user's home directory.  Most user's home directories are in /home/username, but the root user (administrator account) has their home directory in /root.  There is a good reason for this that I won't bother you with unless you are interested.

Have a look at pages 5-6 of my guide.  There's some more detail.

http://guides.radified.com/magoo/guides/linux/linux_partition_intro.html
 
WWW  
IP Logged
 
Rad.in.UbuntuVM
Radmeister
**
Offline


Rad in Ubuntu 9.04 Jaunty
Virtual Machine

Posts: 92


Back to top
Re: UNIX Shell scripting
Reply #13 - Jun 13th, 2009 at 7:58pm
 
do you have a good online link to list of all major commands and their respective options?
 
WWW  
IP Logged
 
Rad.in.UbuntuVM
Radmeister
**
Offline


Rad in Ubuntu 9.04 Jaunty
Virtual Machine

Posts: 92


Back to top
Re: UNIX Shell scripting
Reply #14 - Jun 13th, 2009 at 8:06pm
 
if i run my setUp.pl script from /cgi-bin directory, which sets all permissions for yabb forum installation files, can i just navigate to /cgi-bin, and enter setUp.pl and hit enter, or do i have to first call the perl prgm by entering

perl setUp.pl

??
 
WWW  
IP Logged
 
Pages: 1 2 3 4
Send Topic Print