Any suggested projects for learning bash scripting?
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
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
Re: Any suggested projects for learning bash scripting?
Below is how I like to integrate bash stuff (and CLI apps) with a GUI..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
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
[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]
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
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/*
... 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].
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,
An in-depth exploration of the art of shell scripting:
http://tldp.org/LDP/abs/html/
regards,
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
gerry