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 Wed 27 Aug 2014, 07:11
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Any suggested projects for learning bash scripting?
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
enhu


Joined: 26 May 2009
Posts: 301

PostPosted: Sun 20 Jun 2010, 11:31    Post_subject:  Any suggested projects for learning bash scripting?  

im currently learning bash scripting but don't know what project i should start at least to learn more of it.

can you give me a script that works in puppy please?
i'm will try my best to learn to it and edit scripts :d
Back to top
View user's profile Send_private_message Visit_website 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 11024
Location: Arizona USA

PostPosted: Sun 20 Jun 2010, 13:06    Post_subject:  

Here's one.
Back to top
View user's profile Send_private_message 
sc0ttman


Joined: 16 Sep 2009
Posts: 2376
Location: UK

PostPosted: Sun 20 Jun 2010, 14:56    Post_subject: Re: Any suggested projects for learning bash scripting?  

enhu wrote:
im currently learning bash scripting but don't know what project i should start at least to learn more of it.

can you give me a script that works in puppy please?
i'm will try my best to learn to it and edit scripts :d

Below is how I like to integrate bash stuff (and CLI apps) with a GUI..
I learned most of it off Zigbert and his GTKDialog help thread...

Here is a quick example, of how I add GUIs to bash scripts and functions... Hope this helps..

It is a small GUI that either deletes or creates a file..
It uses bash, gtkdialog and Xdialog (a lovely combo in Puppy)..

The concept is the same for much larger GUIs, which use more advanced bash/functions, etc...

Code:

#!/bin/sh

# set vars to be used
export VERSION='0.1' # strings use single quotes to be literal
export TITLE="example script $VERSION" # use double quotes to show variables in strings
export FILE='/root/text.txt'

# setup functions to do stuff, when buttons are clicked
set -a # this exports functions, so your GUI can see it

# usage: delete_file /path/to/file-to-delete
delete_file () {
 if [ -e "$1" ];then # -e checks if a file/dir exists.. use quotes around the path to enable spaces
    rm "$1"   # 'rm' is delete, $1 is the first parameter given after the function
   Xdialog --title "file removed" --msgbox "$1\n was deleted" 0 0 # tell user with a nice gtk popup
 else
   Xdialog --title "file not removed" --yesno "$1\n was not found.\n\nCreate it?" 0 0 # tell user with a nice gtk popup
   REPLY=$? # get the reply of the above Xdialog
   if [ "$REPLY" = 0 ];then # if answer was yes
      echo "lorem ipsum doner kebab" > "$1" # create the file, with contents "lorem..."   
      Xdialog --title "file created" --msgbox "file created" 0 0 # tell user with a nice gtk popup
   fi
 fi
}

# set the GUI code, using GTKDialog
GUI='<window title="'$TITLE'">
  <hbox>
    <frame>
      <text><label>Choose a file to delete:</label></text>
      <entry tooltip-text="choose a file">
         <default>"'$FILE'"</default> ## this is the file which is passed to the function
         <variable>FILE</variable>
      </entry>
      <button>
         <label>Delete the file</label>
         <input file icon="gtk-delete"></input>
         <action>delete_file $FILE</action> ## this buttons executes function created above
      </button>
      <button>
         <label>Quit</label>
         <input file icon="gtk-quit"></input>
         <action type="exit">EXIT_NOW</action>
      </button>
    </frame>
  </hbox>
</window>'

export GUI="`echo "$GUI" | sed -e 's/##.*//'`"  # enable comments in the GUI
gtkdialog3 --program GUI --center # load the GUI created above, using gtkdialog
unset GUI
exit 0

This may not be what you're looking for but hope it helps..

_________________
Akita Linux, VLC-GTK, Pup Search, Pup File Search
Back to top
View user's profile Send_private_message 
gerry

Joined: 26 Jul 2007
Posts: 946
Location: England

PostPosted: Sun 20 Jun 2010, 17:58    Post_subject:  

There's plenty in Puppy! Have a look at Pnethood.

gerry
Back to top
View user's profile Send_private_message 
enhu


Joined: 26 May 2009
Posts: 301

PostPosted: Mon 21 Jun 2010, 00:55    Post_subject:  

thank all. Very Happy
never thought its that easy to create a GUI, almost same as html Very Happy
Back to top
View user's profile Send_private_message Visit_website 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 11024
Location: Arizona USA

PostPosted: Mon 21 Jun 2010, 07:55    Post_subject:  

That's nice. Why not share what you've learned? Smile
Back to top
View user's profile Send_private_message 
technosaurus


Joined: 18 May 2008
Posts: 4340

PostPosted: Mon 21 Jun 2010, 11:38    Post_subject:  

Often the best way to learn something is by doing - bash is basically a macro for the command line, so if you have found that you need to do certain things frequently in rxvt, why not try integrating these commands into a script.

... or if you want start/stop certain programs in a group (killall-renice_resource_hogs && start_mem-cpu-intensive_programs)

... or to fix an odd hardware issue ... rmmod <badmod> && insmod <goodmod> && run_program <parameter>

...plenty of examples in /usr/bin, /usr/sbin and /usr/local/*

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
ljfr

Joined: 23 Apr 2009
Posts: 176

PostPosted: Mon 21 Jun 2010, 12:46    Post_subject: what about this guide?  

Advanced Bash-Scripting Guide
An in-depth exploration of the art of shell scripting:
http://tldp.org/LDP/abs/html/

regards,
Back to top
View user's profile Send_private_message 
gerry

Joined: 26 Jul 2007
Posts: 946
Location: England

PostPosted: Tue 22 Jun 2010, 03:03    Post_subject:  

I agree with technosaurus- necessity is the mother of invention. I have a very minimal Debian install lurking on my old machine. One problem was that a shutdown button comes as part of the desktop environment, and if you can't afford the space for gnome/kde/... you have to power down either using the command line or the big button on the front of the box. So I wrote a bash script to do it, complete with a menu entry.

gerry
Back to top
View user's profile Send_private_message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 11024
Location: Arizona USA

PostPosted: Tue 22 Jun 2010, 21:51    Post_subject:  

I've found that cookbook-style tutorials are the best way for me to learn. I can take a proven recipe and tinker with it, study it to see how everything works. That's how I learned most of what I know about electronics.
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


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