Bash shell scripting
Bash shell scripting
I want to teach myself shell scripting in BASH.
How do I find out which shell I am currently in (ASH or BASH) from the command line?
How do I swap shells?
What is the difference between ASH and BASH?
Are these the only two shells on Puppy LInux 2.13?
Is there a command that will list all available shells?
How do I find out which shell I am currently in (ASH or BASH) from the command line?
How do I swap shells?
What is the difference between ASH and BASH?
Are these the only two shells on Puppy LInux 2.13?
Is there a command that will list all available shells?
These are all generic Linux queries - use GOOGLE !
echo $ SHELL
bash - ash - sh , etc etc etc
Yes
As default included, Only two in Puppy
echo $ SHELL
bash - ash - sh , etc etc etc
Yes
As default included, Only two in Puppy
I tried to change shell using
# chsh
but received the message
sh: chsh: command not found
why did this not work?
I also tried
# echo $SHELL
and was told
/bin/sh
so I guess the sh is default shell in use.
When I look at the contents of /bin I see ash and sh are shown in light blue text and bash in lime green text. What do these colour differences represent?
# chsh
but received the message
sh: chsh: command not found
why did this not work?
I also tried
# echo $SHELL
and was told
/bin/sh
so I guess the sh is default shell in use.
When I look at the contents of /bin I see ash and sh are shown in light blue text and bash in lime green text. What do these colour differences represent?
First, I read that you said that you wanted to learn to script in bash, well, stick to bash, I don't know why you want to open another shell.une wrote:I don't know why chsh command did not work.
chsh didn't work because there isn't a chsh in Puppy. Really, when a command is not found its because it is not there.
Second:
Here is the best Bash tutorial I've ever seen. It may not be the most complete but after reading it you will feel quite comfortable writing and reading Bash scripts:
http://steve-parker.org/sh/sh.shtml
Third:
Consider that bash scripting is just a way to execute commands in a programmed sequence. So when scripting in bash you will most likelly need to learn those commands. Here is a list of commands that you will need to understand:
grep
sed
awk
cut
tr
Fourth:
Learn regular expressions. Puppy comes with a regular expresions evaluator under the Utilities menu so you can experiment with them.
I hope this helps
[url]http://rarsa.blogspot.com[/url] Covering my eclectic thoughts
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to
Thanks for your detailed help. My understanding is minimal but I thought that every bash shell was the same, containing many commands and that every bash shell would have. When I type chsh at the command line on my Mandrake 10 Linux desktop system (using bash), the command is recognized. But on my Puppy system the same command is not found within bash. I now assume then that even within the same shell, the commands and functionality varies between systems as they may contain different versions of the same shell. Is this correct?
I don't particluarly want to change shell, but my experiments led to this discovery that does not make sense to me yet.
Is it also the case that sh and bash are different shells (but very similar) and that Puppy only has bash? Thus the symbolic link from sh to bash is present so that scripts that reference sh will work in Puppy's bash shell.
I don't particluarly want to change shell, but my experiments led to this discovery that does not make sense to me yet.
Is it also the case that sh and bash are different shells (but very similar) and that Puppy only has bash? Thus the symbolic link from sh to bash is present so that scripts that reference sh will work in Puppy's bash shell.
"sh" Is not a distinct Linux shell variant - & in Puppy - is a symlink to Bash !
Google for different Linux shells available , how they vary.
Bash is the default Linux command parser - it is backwards compatible in most cases - NOT all
As was explained, (by default) inclusion in Puppy has limited ash and Bash CLI parameters.
Temp shelve interest in other shells -concentrate on learning Linux basics & as need dictates, time permits, how to script using Bash.
Puppy forum is for distribution specific variations.
The best way to learn is by backing up (running in RAM mode obviates most full_install_to_hard drive concerns)
Then experiment - asking should be considered - as a last resort when unable to find resources, documentations.
Google for different Linux shells available , how they vary.
Bash is the default Linux command parser - it is backwards compatible in most cases - NOT all
As was explained, (by default) inclusion in Puppy has limited ash and Bash CLI parameters.
Temp shelve interest in other shells -concentrate on learning Linux basics & as need dictates, time permits, how to script using Bash.
Puppy forum is for distribution specific variations.
The best way to learn is by backing up (running in RAM mode obviates most full_install_to_hard drive concerns)
Then experiment - asking should be considered - as a last resort when unable to find resources, documentations.
ash is a small inbuilt shell of busybox.
Busybox is used when Puppy boots, it allows to keep the initial ramdisk small.
Busybox is a binary, that includes several commands, that else are only available as seperate programs.
But this small size has a price: not the full set of options of these programs are available.
So when Puppy booted, it additionally offers the bash, that is loaded from the big file pup_2xx.sfs.
Bash compatibility is required by several programs.
Other shells like ksh or csh have specialized capabilities like support for mathematic functions.
You will find those on universitary systems.
We had one program once, that required csh, so you can extract it from this archive:
http://dotpups.de/files/unsorted-not-pa ... sd-csh.tgz
The original limited sh is used no longer, as GN2 said, it usually is just a symlink to one of the others like the Bash (Bourne again shell), that has become quasi standard in Linux, as it is part of the GNU Utilities from the Free Software Foundation.
The FSF has rewritten several Unix-tools under a free license.
What we commonly know as "GNU/Linux" usually is the Kernel (the "real" Linux) plus the GNU Utilities like bash.
Mark
Busybox is used when Puppy boots, it allows to keep the initial ramdisk small.
Busybox is a binary, that includes several commands, that else are only available as seperate programs.
But this small size has a price: not the full set of options of these programs are available.
So when Puppy booted, it additionally offers the bash, that is loaded from the big file pup_2xx.sfs.
Bash compatibility is required by several programs.
Other shells like ksh or csh have specialized capabilities like support for mathematic functions.
You will find those on universitary systems.
We had one program once, that required csh, so you can extract it from this archive:
http://dotpups.de/files/unsorted-not-pa ... sd-csh.tgz
The original limited sh is used no longer, as GN2 said, it usually is just a symlink to one of the others like the Bash (Bourne again shell), that has become quasi standard in Linux, as it is part of the GNU Utilities from the Free Software Foundation.
The FSF has rewritten several Unix-tools under a free license.
What we commonly know as "GNU/Linux" usually is the Kernel (the "real" Linux) plus the GNU Utilities like bash.
Mark
There is only one bash, there is no such thing as "every bash".une wrote:I thought that every bash shell was the same, containing many commands and that every bash shell would have.
Now I understand your confusion a little bit better:
First
There are different shells, cshell, kornshell, bourne shell, bash. This link may clarify it
http://www.freeos.com/guides/lsst/ch01sec07.html
Second
Not every command that you execute in Bash is a bash command, some are external comands. For example, if you open a bash window and execute "geany" it will open, that does not mean that geany is a bash command, it means that bash executed that command.
chsh is an external command that changes shells,
http://www.die.net/doc/linux/man/man1/chsh.1.html
As puppy only comes with one shell, there is no need for that command.
No, it is not correct.I now assume then that even within the same shell, the commands and functionality varies between systems as they may contain different versions of the same shell. Is this correct?
As an example, every car has the same functionality, but if I put fuzzydice in one car, does not mean that all cars will have them, does it?
No, sh is not "a shell", it is a link to the default shell. So in puppy it is pointing to bash, in other systems it may be pointing to some other shell.Is it also the case that sh and bash are different shells
I hope this clarifies the issue.
[url]http://rarsa.blogspot.com[/url] Covering my eclectic thoughts
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to
So it seems that the command chsh executes an application (if that application has been installed on the system) that changes the shell. This command does not execute a function built into the shell itself, unlike commands such as rm and grep. Do I have this much correct?
Sorry for not being distro specific, but I figure I may as well finish this thing now.
Sorry for not being distro specific, but I figure I may as well finish this thing now.
No, don't stop now. This is a subject which has needed clarification for some time. I'm adding this thread to the Beginners sticky index, under Educational discussions. Thanks to everyone who contributed helpful explanations.
The concept is correct: there are built in commands that are part of bash. There are other commands that are sand alone programs.une wrote:This command does not execute a function built into the shell itself, unlike commands such as rm and grep. Do I have this much correct?.
FYI...rm and grep are external commands, not a shell commands.
Here is the list of built in commands
http://linux.about.com/library/cmd/blcmdl1_builtin.htm
Whenever you are in doubt you can execute "which" with a valid command
Code: Select all
which <command>
e.g.
which grep
Note that I said "valid command", if you use "which" with an invalid command or a program that is not in your path, then it will complain too.
[url]http://rarsa.blogspot.com[/url] Covering my eclectic thoughts
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to
Bash is a very powerful command shell - a "shell" because it may stand alone - without need for most GUI functions.
As in nature a "shell" may contain most anything inside it.
Bash has many desirable features,>
Auto command line completion_
"Wildcard" letter substitution
"Built-in" Internal & external functions
A "prompt" that is user configurable & may enfold many functions
"Reserved" character functions - (Bash internal use only)
Built as an execute only - or await user input {interactively}
The login shell (in the INITIAL = initrd boot image) usually ASH is an example of "interactive" use
Once control is passed to the kernel. file system mounted, which CLI used has been determined by the distribution
Part of the confusion arises in ability to make a script executable.
An executable may include - functions as desired to call other internal/external commands,
take those results and perform other actions.
The script may also embed other languages/functions that are invoked If/when the dependencies
for them are available as dynamic libraries -already installed on System.
What you now have is a executable - coded partially in binary and partially in text.
If some binary contains their dependencies in the code - it is a STATIC binary
= Self contained, the dependencies are included
Apps built requiring dynamic libraries - are compiled with specific dependencies.
If those dependencies are not met (not available), versions don't match -
or the command executable path environment is incorrect-
The output is intercepted by the error handling procedures of the kernel -
In most cases, an error Msg is output to screen (I.E. segment fault) and process halted to limit further system damage.
In extreme error cases, a kernel "dump" is output (contents of memory locations of events)
In others - the system may "lock" (kernel panic) > a kernel freeze - unable to continue ~ a power reset is Req'd.
Please read Bash manuals and for Linux basics, see such as the YoLinux (URL)
It will be a big aid to purchase such as the O'Reilly manual "Linux in a Nutshell"
It is much the same as the built-in system help (man or info pages), but w/explanations.
Their prime use however is as an "cheat-sheet" to recall parameter syntax.
They are not suitable to LEARN Bash... any more than a dictionary may teach a new language.
One of best Bash manuals is downloadable, BASH - on-line
Any data in this forum thread was available on line.
As in nature a "shell" may contain most anything inside it.
Bash has many desirable features,>
Auto command line completion_
"Wildcard" letter substitution
"Built-in" Internal & external functions
A "prompt" that is user configurable & may enfold many functions
"Reserved" character functions - (Bash internal use only)
Built as an execute only - or await user input {interactively}
The login shell (in the INITIAL = initrd boot image) usually ASH is an example of "interactive" use
Once control is passed to the kernel. file system mounted, which CLI used has been determined by the distribution
Part of the confusion arises in ability to make a script executable.
An executable may include - functions as desired to call other internal/external commands,
take those results and perform other actions.
The script may also embed other languages/functions that are invoked If/when the dependencies
for them are available as dynamic libraries -already installed on System.
What you now have is a executable - coded partially in binary and partially in text.
If some binary contains their dependencies in the code - it is a STATIC binary
= Self contained, the dependencies are included
Apps built requiring dynamic libraries - are compiled with specific dependencies.
If those dependencies are not met (not available), versions don't match -
or the command executable path environment is incorrect-
The output is intercepted by the error handling procedures of the kernel -
In most cases, an error Msg is output to screen (I.E. segment fault) and process halted to limit further system damage.
In extreme error cases, a kernel "dump" is output (contents of memory locations of events)
In others - the system may "lock" (kernel panic) > a kernel freeze - unable to continue ~ a power reset is Req'd.
Please read Bash manuals and for Linux basics, see such as the YoLinux (URL)
It will be a big aid to purchase such as the O'Reilly manual "Linux in a Nutshell"
It is much the same as the built-in system help (man or info pages), but w/explanations.
Their prime use however is as an "cheat-sheet" to recall parameter syntax.
They are not suitable to LEARN Bash... any more than a dictionary may teach a new language.
One of best Bash manuals is downloadable, BASH - on-line
Any data in this forum thread was available on line.
Thanks again. I think I need to do some generic Linux research.
I am using a book called;
"Linux & Unix Programming Tools" by Sarwar
to get started on my Linux programming quest. It is actually part of a computer science course I am taking via the Internet.
I am starting to work my way into the book and am finding other commands that my Puppy Linux system does not recognize. The latest command I tried to use that Puppy Linux did not recognize was whereis.
My Linux system at home (Mandrake 10) recognizes commands such as chsh and whereis. It seems there is a whole other set of commands that one commonly uses from the Linux command line that are not a built in within BASH or located elsewhere in Puppy Linux.
My apologies Gn2 but I did not understand all of what you detailed in your last post, as I said I will do more research elsewehere.
However, is there a package I can download and install (then include in a remastered CD for constant use) that will make available from the command line the entire range of Linux commands that are commonly used?
I looked at the the built in commands listing suggested in this thread and found some examples that have confused me a little. Stick with me here if you have time, following are my experiments;
In this thread it has been mentioned that grep is not a built in BASH command, thus as expected to me when I execute the following I get a response as follows from the system;
$which grep
/bin/grep
This indicates to me that the command grep is not built in within BASH and the application that is grep is located in /bin.
break is a built in command within BASH apparently, so when I execute
$which break
$
I get no response at all, just another prompt as shown above. Does this lack of system response indicate that break is a BASH built in command?
printf is also an built in command within BASH it seems, however when I execute the following I get a response as follows;
$which printf
/usr/bin/printf
This confuses me as this indicates to me that to execute the printf command the system uses an external application stored in /usr/bin.
whereis is not available at all, however when I execute the following I get a response as follows;
$which whereis
$
This confuses me as this lack of system response is the same as for break, which I deduced meant it was a BASH built in command.
There are some other "non BASH built in" commands available in my Puppy Linux system such as date
$which date
/bin/date
and time
$which time
/usr/bin/time
which are included in my Puppy Linux.
Thus I am confused as to why what I think are supposed to be BASH built in commands, seem to execute from external (to BASH) locations (eg printf)
I am also confused why some external commands such as grep are included in Puppy Linux and why others are not (eg whereis)
Perhaps there may be other commands I will be asked to use when working through my textbook that are not either built in within BASH nor available from elsewhere in the Puppy Linux OS.
I want to be able to work through this textbook using Puppy Linux.
I am using a book called;
"Linux & Unix Programming Tools" by Sarwar
to get started on my Linux programming quest. It is actually part of a computer science course I am taking via the Internet.
I am starting to work my way into the book and am finding other commands that my Puppy Linux system does not recognize. The latest command I tried to use that Puppy Linux did not recognize was whereis.
My Linux system at home (Mandrake 10) recognizes commands such as chsh and whereis. It seems there is a whole other set of commands that one commonly uses from the Linux command line that are not a built in within BASH or located elsewhere in Puppy Linux.
My apologies Gn2 but I did not understand all of what you detailed in your last post, as I said I will do more research elsewehere.
However, is there a package I can download and install (then include in a remastered CD for constant use) that will make available from the command line the entire range of Linux commands that are commonly used?
I looked at the the built in commands listing suggested in this thread and found some examples that have confused me a little. Stick with me here if you have time, following are my experiments;
In this thread it has been mentioned that grep is not a built in BASH command, thus as expected to me when I execute the following I get a response as follows from the system;
$which grep
/bin/grep
This indicates to me that the command grep is not built in within BASH and the application that is grep is located in /bin.
break is a built in command within BASH apparently, so when I execute
$which break
$
I get no response at all, just another prompt as shown above. Does this lack of system response indicate that break is a BASH built in command?
printf is also an built in command within BASH it seems, however when I execute the following I get a response as follows;
$which printf
/usr/bin/printf
This confuses me as this indicates to me that to execute the printf command the system uses an external application stored in /usr/bin.
whereis is not available at all, however when I execute the following I get a response as follows;
$which whereis
$
This confuses me as this lack of system response is the same as for break, which I deduced meant it was a BASH built in command.
There are some other "non BASH built in" commands available in my Puppy Linux system such as date
$which date
/bin/date
and time
$which time
/usr/bin/time
which are included in my Puppy Linux.
Thus I am confused as to why what I think are supposed to be BASH built in commands, seem to execute from external (to BASH) locations (eg printf)
I am also confused why some external commands such as grep are included in Puppy Linux and why others are not (eg whereis)
Perhaps there may be other commands I will be asked to use when working through my textbook that are not either built in within BASH nor available from elsewhere in the Puppy Linux OS.
I want to be able to work through this textbook using Puppy Linux.
the free version of Mandriva is 4,438MB (commercial version is larger) ... Puppy is less than 80MBMy Linux system at home (Mandrake 10) recognizes commands such as chsh and whereis
i'm not sure, but i think there is a dotpup package of the GNU utilities somewhereis there a package I can download
which grep shows that there is an executable file named grep in one of the directories in the PATH (type echo $PATH) ... whether grep is a bash builtin function, or not ... if there is no executable file named grep in a dir in PATH, it will not display a result ... whether grep is a bash builtin function, or notThis indicates to me that the command grep is not built in within BASH and the application that is grep is located in /bin
which does not tell you about bash builtin functions
no, it tells you that there is no executable file named break in the PATH dirsDoes this lack of system response indicate that break is a BASH built in command?
which tells you that there is an executable file named printf in /usr/bin ... this does not tell you whether there is a bash builtin function named printfThis confuses me as this indicates to me that to execute the printf command the system uses an external application stored in /usr/bin
if you type ash, you will run Busybox's ash shell ... if you then type help, it will show you a list of builtin functions in the ash shell ... printf is not an ash builtin function, so ash will run an external executable file if you run the printf command
if you type help in a bash shell, you will see that printf is a bash builtin function ... if you run the printf command in a bash/sh shell, you will be running the internal bash function, not the external executable file
this means there is no executable file named whereis in PATHThis confuses me as this lack of system response is the same as for break, which I deduced meant it was a BASH built in command
there is a similar and useful bash script called where ... dotpup package here: http://www.murga-linux.com/puppy/viewtopic.php?&t=10469
grep is extremely useful (essential) ... whereis is not essential at all (obviously, since Puppy runs without it)I am also confused why some external commands such as grep are included in Puppy Linux and why others are not (eg whereis)
if you delete /bin/grep, you will find that Puppy will be severely broken ... many programs will no longer work ... Puppy may no longer be able to finish booting
Puppy is 80 megs, not 4 gigs ... Puppy is different, it is designed to be small and fast and to run completely in ram ... it is not possible to small and fast and to run completely in ram and to have installed by default every program and utility and library that a distro like Mandriva has installedI want to be able to work through this textbook using Puppy Linux