Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 24 Jul 2014, 00:40
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
HOWTO: Scripting - Great reference
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [11 Posts]  
Author Message
rarsa


Joined: 29 May 2005
Posts: 3053
Location: Kitchener, Ontario, Canada

PostPosted: Sat 07 Jan 2006, 12:02    Post subject:  HOWTO: Scripting - Great reference  

One of the give aways in my LUG was a very handy Bash pocket reference

Today, by chance, I found the same reference as a PDF.

If you do shell scripting you sure want this reference at your side.

Although it is bash specific, most of it applies to Puppy's default shell.

http://database.sarang.net/study/bash/bash.pdf

And now that you are here. You may also be interested in this Bourne shell tutorial:

http://steve-parker.org/sh/sh.shtml

I've read many, but this one is very well organized and presented.

(have I mentioned that I met Steve Bourne and we chatted for a few minutes while waiting for drinks at a conference?)
Back to top
View user's profile Send private message Visit poster's website 
kethd

Joined: 20 Oct 2005
Posts: 451
Location: Boston MA USA

PostPosted: Sun 08 Jan 2006, 11:54    Post subject:  

BASH is the default command line shell in current Puppy, at least when you are within Xwin -- and future Puppy is said to be all bash all the time, ash will be deprecated...
Back to top
View user's profile Send private message 
puppypilgrim

Joined: 07 Jun 2005
Posts: 80
Location: Vancouver, Canada

PostPosted: Tue 10 Jan 2006, 14:28    Post subject:  

Thank you for posting such a handy reference. Scouring the net only yields bits and pieces.
Back to top
View user's profile Send private message Yahoo Messenger 
jmarsden


Joined: 31 Dec 2005
Posts: 263
Location: California, USA

PostPosted: Tue 10 Jan 2006, 16:20    Post subject:  

I've already mentioned these in threads elsewhere on these forums, I think, but since we have a new thread just for Bash documentation and tutorials, here they are:

The canonical source of info on Bash scripting is the Bash Reference Manual . In the Linux world, a decent Bash scripting tutorial is the Advanced Bash Scripting Guide. This is not actually "advanced", in that it starts from basics, so scripting newcomers should not be put off by its title. It's first paragraph reads:
Quote:
This tutorial assumes no previous knowledge of scripting or programming, but progresses rapidly toward an intermediate/advanced level of instruction . . . all the while sneaking in little snippets of UNIX® wisdom and lore. It serves as a textbook, a manual for self-study, and a reference and source of knowledge on shell scripting techniques. The exercises and heavily-commented examples invite active reader participation, under the premise that the only way to really learn scripting is to write scripts.

Jonathan
Back to top
View user's profile Send private message 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Mon 23 Jan 2006, 17:05    Post subject:  



I wrote a shellscript "mini-calc", that might be helpfull.

It does:
- Open itself in a coloured rxvt when clicked in ROX.
- inputs words
- inputs numbers only
- has a kind of "main-menu".
- runs a external program that is not so easy to use, the commandline-calculator "bc".

"bc" can do floatingpoint-calculations, while the internal bash-calculations are limited to integer.

This program is not "better" than bc, in fact it is "stupid",as it just allows to add 2 numbers.
But it is not inteded to be a good calculator, but just to be a demo how you can realize the points mentioned above.

It requires 2 Dotpups:
bc and nohup
bc also might require libreadline4

nohup runs a command (in the example leafpad or beaver to show the sourcecode), without closing it, when the "calling" program (the rxvt-window) is closed.

http://dotpups.de/dotpups/System_Utilities/nohup.pup (6 kb)
http://dotpups.de/dotpups/System_Utilities/bc-calculator.pup (48 kb)
http://noforum.de/dotpups/libreadline-so-4.pup (82 kb)

And here is the "mini-calc" -script:

Code:
#!/bin/bash

#------------------------------------------------
#-- start in a new console-window
#------------------------------------------------

if [ "$1" != "rxvt" ];then

  rxvt -title mini-calc +sb -cr green -bg yellow -geometry 40x10+200+200 -e $0 rxvt &
  exit 0

fi

#-------------------------------------
#-- simple "input" -function
#-------------------------------------

readkeys(){

  read keypress
  if [ "$keypress" == "exit" ];then
    xmessage -center goodbye!
    exit 0
  fi

}

#-------------------------------------------------------------------------------
#-- simple "input" -function with check for numbers only
#-------------------------------------------------------------------------------
readnumber(){

  clear
  echo -e "enter \"exit\" to quit.\n"
  echo -e $infotext
  read keypress
  if [ "$keypress" == "exit" ];then
    xmessage -center goodbye!
    exit 0
  fi

  #-- just allow numbers and decimal-point
  numcheck=`echo $keypress | sed "s/[0-9]//g" | sed "s/\.//"`

  if [ $numcheck ]; then
   readnumber
  fi
}

#--------------------------------------------------------------------------
#--- addition of 2 values with external calculator "bc"
#--------------------------------------------------------------------------
runbcplus(){

  bc -l<<END-OF-INPUT
  $va+$vb
  quit
END-OF-INPUT
}

#-------------------------
#-- main-script
#-------------------------

#-------------------------------------------------------
#-- read 2 numbers and print the sum
#-------------------------------------------------------


infotext="welcome to mini-calc\nenter first number"
readnumber
va=$keypress

infotext="enter second number"
readnumber
vb=$keypress

clear
echo Result: $va + $vb = `runbcplus`
echo

#-------------------------------------------------------------------.
#-- endless loop until user exits ("main-menu")
#-------------------------------------------------------------------

while [ "$keypress" != "exit" ];do

  echo enter \"exit\" to quit
  echo enter \"code\" to view the source
  echo enter \"r\" to restart again
  readkeys
  if [ "$keypress" == "code" ];then
    nohup leafpad $0 1>/dev/null || beaver $0 1>/dev/null&
  fi
  if [ "$keypress" == "r" ];then
    $0 rxvt
  fi
  clear
done


Save as /usr/local/bin/minicalc
Make it executable:
chmod 755 /usr/local/bin/minicalc
Click it in ROX.

Germans might like this introduction:
http://www.linuxfibel.de/kapitel2.htm
http://www.linuxfibel.de/kapitel7.htm

Mark
Back to top
View user's profile Send private message Visit poster's website 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Mon 23 Jan 2006, 19:45    Post subject: Ash is a smaller, simplified Bash  

kethd wrote:
BASH is the default command line shell in current Puppy, at least when you are within Xwin -- and future Puppy is said to be all bash all the time, ash will be deprecated...


Many thanks to MU for his efforts in educating us about scripting. Smile

This is my understanding which needs further clarification:

Puppy uses Ash and Busybox and the full Bash commands where these are required for a more complete implementation.
Bash is a (large) collection of C commands that can be called from the command line. Many of these commands are with their most used functions linked in one C program - Busybox. Thus Ash is a smaller, simplified Bash.

As far as I am aware the intention at one point was to move to the full Bash commands BUT it was considered wasteful of space resources and so this has not been implemented.

Is that right? Confused

_________________
Puppy WIKI
Back to top
View user's profile Send private message Visit poster's website 
jmarsden


Joined: 31 Dec 2005
Posts: 263
Location: California, USA

PostPosted: Wed 25 Jan 2006, 04:36    Post subject: Re: Ash is a smaller, simplified Bash  

Lobster wrote:
Puppy uses Ash and Busybox and the full Bash commands where these are required for a more complete implementation.
Bash is a (large) collection of C commands that can be called from the command line. Many of these commands are with their most used functions linked in one C program - Busybox. Thus Ash is a smaller, simplified Bash.

Well, Bash is just the shell itself. Not the collection of executables the shell can run if you ask it to. The only commands that are part of bash are the "built in" ones. In the MSDOS world these would be the "internal commands". Type the word "help" at a bash shell prompt to see its list of these. You can add aliases and shell functions to these, and they will also run "inside" Bash itself.

All other commands you can execute from Bash (or any other shell, in general) by typing their name are scripts or executable programs that are on disk somewhere and in a directory in your $PATH . In the MSDOS world they are "external commands" Some of those (many of the normal Unix commands) are written in C, but others are not.
Quote:
As far as I am aware the intention at one point was to move to the full Bash commands BUT it was considered wasteful of space resources and so this has not been implemented.

Since the Bash shell is in Puppy, the full set of (internal) Bash commands is there now. As for replacing all BusyBox commands with their individual "normal Linux" equivalents, that could be wasteful of disk space for small systems. What seems to be happening is more that as a particular Busybox command is found to lack some option or feature that Puppy needs, the "real" equivalent command is added to Puppy instead of the "cut down" Busybox version.

Oh, and strictly speaking, ash is the Almquist shell, which is not a cut-down bash, but rather a free implementation of a shell that tries to be as close as possible to the original Bourne shell. Most Linuxes, I think including Puppy, use a version of ash derived from the NetBSD /bin/sh codebase. In general, coding shell scripts for ash will ensure wide compatibility across multiple Unix and Unix-like systems, coding for Bash is more pleasant (you have more language features!), but often not quite as portable. If you do write a script that uses Bash features, be sure to put #!/bin/bash at the top of it, so that it will work on systems where Bash is installed but /bin/sh is ash or a commercial Bourne shell.

That may be more detail that you really wanted... Smile

Jonathan
Back to top
View user's profile Send private message 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Wed 25 Jan 2006, 06:03    Post subject: Re: Ash is a smaller, simplified Bash  

jmarsden wrote:

That may be more detail that you really wanted... Smile

Jonathan


That is very useful Smile thanks for clarifying
Now I just have to read this:
http://www.gnu.org/software/bash/manual/bashref.html

Wot no pictures? Wink

_________________
Puppy WIKI
Back to top
View user's profile Send private message Visit poster's website 
Guest
Guest


PostPosted: Thu 26 Jan 2006, 03:08    Post subject: Re: Ash is a smaller, simplified Bash  

Lobster wrote:
Wot no pictures? Wink

Maybe you could read http://www.tldp.org/LDP/abs/html/ first, the other document I linked to in my 10 Jan 2006 post in this thread. It may not quite have pictures, but it does have plenty of examples. The Bash Reference Manual really is just that... use it to refer to, when you need to do something you are pretty sure Bash can do, but you need the details on how. Use the LDP tutorial to learn the basics (OK, maybe a bit more than just the basics) of shell scripting first. Few people enjoy reading reference manuals cover to cover!

On many Linux systems (but not Puppy for size reasons) there is also the Bash man page, which perhaps lies somewhere between the tutorial and the ref manual -- and is what I used to learn Bash scripting!

Jonathan
Back to top
Guest
Guest


PostPosted: Fri 27 Jan 2006, 06:47    Post subject:  

http://tiger.la.asu.edu/bash_tutorial.htm
Back to top
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Tue 04 Apr 2006, 15:10    Post subject: Here is a nice intro to bash  

Here is a nice intro to bash
http://www.codecoffee.com/tipsforlinux/articles2/043.html

_________________
Puppy WIKI
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [11 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1025s ][ Queries: 12 (0.0193s) ][ GZIP on ]