Any suggested projects for learning bash scripting?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
enhu
Posts: 302
Joined: Wed 27 May 2009, 02:13
Contact:

Any suggested projects for learning bash scripting?

#1 Post by enhu »

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

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#2 Post by Flash »

Here's one.

User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

Re: Any suggested projects for learning bash scripting?

#3 Post by sc0ttman »

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: Select all

#!/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..
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

gerry
Posts: 986
Joined: Thu 26 Jul 2007, 21:49
Location: England

#4 Post by gerry »

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

gerry

User avatar
enhu
Posts: 302
Joined: Wed 27 May 2009, 02:13
Contact:

#5 Post by enhu »

thank all. :D
never thought its that easy to create a GUI, almost same as html :D

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#6 Post by Flash »

That's nice. Why not share what you've learned? :)

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#7 Post by technosaurus »

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/*
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

ljfr
Posts: 176
Joined: Thu 23 Apr 2009, 08:35

what about this guide?

#8 Post by ljfr »

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

regards,

gerry
Posts: 986
Joined: Thu 26 Jul 2007, 21:49
Location: England

#9 Post by gerry »

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

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#10 Post by Flash »

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.

Post Reply