LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-15-2011, 06:37 AM   #1
sujitkulkarni
LQ Newbie
 
Registered: Feb 2011
Location: Pune, India
Distribution: Ubuntu 9.10
Posts: 29

Rep: Reputation: 0
what is shell scripting?


What is shell scripting? what is 'bash'?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 02-15-2011, 06:54 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

Asked and answered a million times before. Please put in some work and Google, there are so many documents online that go into detail on what shell scripting and Bash is.

Kind regards,

Eric
 
Old 02-15-2011, 06:56 AM   #3
ozanbaba
Member
 
Registered: May 2003
Location: Tengiz
Distribution: Slackware64 14.1
Posts: 672

Rep: Reputation: 94
It's God's judgment on humanity. And use a web search like DuckDuckGo.
 
0 members found this post helpful.
Old 02-15-2011, 07:17 AM   #4
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,674
Blog Entries: 29

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
BASH: Bourne Again shell

Bash is a type of shell in Unix/Linux.

A shell in Linux/Unix means something which takes as input the user specified
commands, executes them and gives us the output.

Every command recognized by the shell is actually a program whose executable is
stored in the folders like /bin.

Example:
ls is a command which lists all the files in a folder.
So here we are using ls command to list out all the folders in the
root directory. (root directory is represented by / in bash,
so when we say, /bin, it means the bin directory in the root folder)

Code:
anisha@linux-uitj:~> ls /
bin   etc         initrd.lz   media  proc  selinux  tmp  vmlinuz
boot  home        lib         mnt    root  srv      usr
dev   initrd.img  lost+found  opt    sbin  sys      var
All the files in the below output are recognized by the shell as valid executables.
Example:
In the below example notice the ls command itself listed inside the /bin
folder as an executable.
Code:
anisha@linux-uitj:~> cd /bin
anisha@linux-uitj:/bin> ls
arch                  df             gzip         mkdir          pwd              sync
awk                   dmesg          hostname     mknod          readlink         tar
csh                   fgconsole      loadkeys     pidof          setserial        usleep
date                  fgrep          loadunimap   ping           sh               vi
dbus-cleanup-sockets  fillup         logger       ping6          showconsolefont  vim
dbus-daemon           fsync          login        pkill          showkey          vim-normal
dbus-monitor          fuser          ls           ps             sleep            ypdomainname
dbus-send             gawk           lsmod        psfaddtable    sort             zcat
deallocvt             gunzip         md5sum       psfxtable      su
If the shell recognizes the commands, it executes its executable file.
The commands recognized by the shell usually call dozens of other functions dealing
directly with the Linux kernel.

It looks too simple??, to know which functions does ls call "internally" to get the list of the files, there is another command named 'strace':

The titles which you see in red colour below are actually the functions called by ls, internally.
Code:
anisha@linux-uitj:~> strace ls                                                 
execve("/bin/ls", ["ls"], [/* 89 vars */]) = 0                                          
brk(0)                                  = 0x618000                                      
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa7724ef000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa7724ee000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)          
open("/usr/lib64/mpi/gcc/openmpi/lib64/tls/x86_64/librt.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)                                                                                                  
stat("/usr/lib64/mpi/gcc/openmpi/lib64/tls/x86_64", 0x7fff75b561b0) = -1 ENOENT (No such file or directory)                                                                                                       
open("/usr/lib64/mpi/gcc/openmpi/lib64/tls/librt.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
...                                                                                  
write(1, "alltray-0.7.4dev.tar.gz\t\t\t opera"..., 55alltray-0.7.4dev.tar.gz                     opera-10.62-6438.x86_64.rpm                                                                                      
) = 55                                                                                                   
write(1, "aptoncd\t\t\t\t\t osm2pgsql\n", 23aptoncd                                      osm2pgsql       
) = 23                                                                                          ...         
anisha@linux-uitj:~>
and finally check out the following:
1. http://tldp.org/LDP/Bash-Beginners-Guide/html/
2. http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
3. http://tldp.org/LDP/abs/html/

Last edited by TheIndependentAquarius; 02-16-2011 at 05:01 AM. Reason: sorted things out / typo
 
6 members found this post helpful.
Old 02-15-2011, 08:14 AM   #5
honeybadger
Member
 
Registered: Aug 2007
Location: India
Distribution: Slackware (mainly) and then a lot of others...
Posts: 855

Rep: Reputation: Disabled
@Anisha: Do you think the OP even can _read_ the script. Heck, I gave up after the second line. I have however bookmarked the page and will read this later.
@OP: Bash scripting is something *nix folks do. It is actually used to scare newbies like you. Hang in there, you would eventually understand.
 
0 members found this post helpful.
Old 02-15-2011, 08:18 AM   #6
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,674
Blog Entries: 29

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
Quote:
Originally Posted by SilverBack View Post
@Anisha: Do you think the OP even can _read_ the script.
What script? I only explained him the meaning of bash.

Quote:
Originally Posted by SilverBack View Post
@OP: Bash scripting is something *nix folks do. It is actually used to scare newbies like you. Hang in there, you would eventually understand.
and writing statements like these is NOT helpful specially when you are talking to a newbie!
 
Old 02-15-2011, 08:40 AM   #7
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Quote:
Originally Posted by SilverBack View Post
@Anisha: Do you think the OP even can _read_ the script. Heck, I gave up after the second line. I have however bookmarked the page and will read this later.
@OP: Bash scripting is something *nix folks do. It is actually used to scare newbies like you. Hang in there, you would eventually understand.
Hello,

Sorry to disagree with you but what Anisha posted was in my opinion a very clear and more then complete explanation of what Bash is, and all of that in easy to understand terms. Heck, it's a lot more then what I would post to explain something that's basic knowledge and easy to find on the internet (hence my previous post).

Making a statement like you do, bringing down the importance of Bash (and for what it's worth other shells), gives a very wrong image of Linux/Unix. How is OP to understand like you point out he eventually will, when you 'bash' a perfectly good basic explanation?

Kind regards,

Eric
 
1 members found this post helpful.
Old 02-15-2011, 08:45 AM   #8
hughetorrance
Member
 
Registered: Aug 2009
Location: London North West
Distribution: x86_64 Slack 13.37 current : +others
Posts: 459

Rep: Reputation: 59
Talking kernel and shell

Quote:
Originally Posted by sujitkulkarni View Post
What is shell scripting? what is 'bash'?
Asking that is like asking how long is a piece of string...as like in a nut (hazel nut,walnut,etc etc)the kernel is surrounded by the shell...

http://www.freeos.com/guides/lsst/ good luck

Google "shell scripting" and "bash" without the parentheses
 
Old 02-15-2011, 08:50 AM   #9
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,674
Blog Entries: 29

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
Eric, thank you, for the soothing words you wrote as a comment in the reputation column. I enjoyed them so much that I was forced to make this post, just to thank you.
 
Old 02-15-2011, 08:54 AM   #10
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi Anisha,

No thanks necessary, in my opinion you did a great job with that post in very understandable words. Should be appreciated by all newbies looking for a simple explanation of something that can go to very high complexity. Thank you for taking the time to post it. I'm sure a lot of users will agree with me. Statements like SilverBack's one don't add to the valor of Linux at all.

Kind regards,

Eric
 
Old 02-15-2011, 09:08 AM   #11
citi
Member
 
Registered: Jan 2011
Location: Lithonia, GA
Distribution: Ubuntu,Fedora,puppy,CentOS
Posts: 36

Rep: Reputation: 6
Document

here is the pdf "Introduction to bash scripting" this should give you a good foundation along with Anisha's examples
Attached Files
File Type: pdf ShellIntro.pdf (124.3 KB, 23 views)
 
2 members found this post helpful.
Old 02-15-2011, 09:10 AM   #12
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi citi,

Very nice, thanks for sharing it. I'm sure it'll be of use to someone.

Kind regards,

Eric
 
Old 02-15-2011, 09:14 AM   #13
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
But it still seems very odd and inappropriate to introduce a newbie to bash using strace...

Anyway, bash is the program that interprets the commands you type at a terminal, and a shell script is a file full of commands that can be run by the shell so you don't have to type them one by one.

Like Anisha said, commands are actaully executable programs in certain directories. But some are built into the shell.

The shell also has syntax for variables, if-then-else statements, wildcards, math, etc.

Last edited by MTK358; 02-15-2011 at 09:18 AM.
 
Old 02-15-2011, 09:17 AM   #14
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Quote:
Originally Posted by MTK358 View Post
But is still seems very odd to introduce a newbie to bash using strace...
Hi,

I thought it was a nice touch using strace to show that it's not all that simple as just using ls but that there's a 'world' of complex things below what we use on a regular basis. Something about what most newbies don't even think about but can be very useful information. If you want to tame the beast it's best to understand it's nature

Kind regards,

Eric
 
Old 02-15-2011, 09:34 AM   #15
citi
Member
 
Registered: Jan 2011
Location: Lithonia, GA
Distribution: Ubuntu,Fedora,puppy,CentOS
Posts: 36

Rep: Reputation: 6
Your welcome Eric, just trying to help in any way possible
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
LXer: Terminal functions for shell scripting with Shell Curses LXer Syndicated Linux News 0 03-27-2008 12:50 AM
SHELL scripting/ shell functions mayaabboud Linux - Newbie 6 12-26-2007 09:18 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 04:32 PM


All times are GMT -5. The time now is 08:12 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration