Bash Shell: Object Oriented
Object orientation is getting a more and more popular paradigm – and MS has tried to create a object oriented shell for the Windows Vista operating system. However a traditional BASH-shell can also be scripted to mimic object orientation using a number of aliases – listed here bellow.
# object-oriented-like behaviour
alias alias.delete='unalias'
alias alias.edit='$EDITOR ~/.aliases.bash'
alias alias.list='alias'
alias alias.list.terse='alias.list | cut -d " " -f 2- | cut -d "=" -f1'
alias alias.new='alias'
alias alias.reload='. ~/.aliases.bash'
alias alias.save='alias > ~/.aliases.bash'
alias dir.change='cd'
alias dir.contents='ls'
alias dir.contents.long='dir.contents -la'
alias dir.current='pwd'
alias dir.delete='rmdir'
alias dir.list='ls'
alias dir.list.help='ls --help'
alias dir.move='mv'
alias dir.new='mkdir'
alias dir.remove='rmdir'
alias dir.rename='mv'
alias dir.stat='stat'
alias dir.properties='stat'
alias sys.date='date'
alias sys.system='uname'
alias file.contents='cat'
alias file.contents.backwards='tac'
alias file.contents.pager='less'
alias file.contents.reverse='rev'
alias file.cut='cut'
alias file.delete='rm'
alias file.head='head'
alias file.grep='grep'
alias file.join='join'
alias file.move='mv'
alias file.new='touch'
alias file.paste='paste'
alias file.properties='stat'
alias file.rename='mv'
alias file.sort='sort'
alias file.stat='stat'
alias file.tail='tail'
alias file.type='file'
alias function.delete='unset -f'
alias function.edit='$EDITOR ~/.functions.bash'
alias function.list.detailed='declare -f'
alias function.list.terse='declare -F | cut -d "=" -f2- '
alias function.new='function'
alias function.reload='. ~/.functions.bash'
alias function.save='declare -f > ~/.functions.bash '
alias user.delete='userdel'
alias user.id='id'
alias user.list='sort /etc/passwd'
alias user.me='whoami'
alias user.new='useradd'
alias user.properties='id'
alias user.stat='id'
alias variable.delete='unset'
alias variable.exported.list='declare -x'
alias variable.list='set'
alias variable.new='declare'
Related posts:
- Bash shortcuts tips and tricks
- Howto Convert Text File From UTF-8 to ISO-8859-1 Encoding
- Rethinking the GUI (Graphical User Interface) and the CLI (Command Line Interface)
- What is the coolest thing you can do using Linux that you can’t do with Windows or on a Mac?
- Top 10 Free Windows 7 Applications
- SSH Key for Login Without Password
- Ubuntu: Print to PDF or PDF Export
- Crack pdf password with pdfcrack
- X11 for Windows XP and Vista
- Xen Howto: Install Windows
Popular Related Items »
Incoming search terms
- object oriented bash
- bash object oriented
- bash objects
- bash object
- object oriented shell
- bash oop
- symbian bash
- object oriented shell scripting
- bash for symbian
- bash symbian
- object oriented shell script
- bash oo
- object fucking
- objects in bash
- shell script objects
- oo shell
- symbian bash shell
- object fuck
- oop bash
- objekt fuck
- bash properties file
- bash shell for symbian
- Object-Oriented Shell
- bash object oriented programming
- object oriented bash scripting
- object bash
- bash variable naming convention
- object-oriented bash
- oo bash
- fucking objects
- linux object oriented shell
- shell script object
- shell script oo
- objekt fucking
- linux object shell
- fuck oop
- bash object orientation
- object oriented programming bash
- bash shell symbian
- bash shell for windows vista
- object oriented programming in bash
- linux object oriented
- objects bash
- shell oop
- object shell linux

Curtis said,
January 6, 2008 @ 2:21
Why the hell would you want an object-oriented BASH script you dumb fuck? Use Python, Perl, or any other scripting language for that.
Leave BASH the hell alone – it’s supposed to be simple and effective. Changing programming paradigms is fucking retarded and should not be done for a command line.
Simon said,
April 9, 2008 @ 10:14
I would like to know what’s so object-oriented about “dir.delete”.
Just because there is a dot “.” in the alias name it doesnt make it OO, IMHO.
(OO, IMHO … nice wordplay btw.)
If it truely was OO it would be more like “/path/to/dir.delete()” at commandline level with no other preceding command.
Like if you was typing:
user@localhost ~ > .bashrc.delete()
user@localhost ~ > .mozilla.copy(~/backups/)
or something like that.
In fact, one could truely mimic OO with one super-large-script which must be omitted on every cmdline typed in, and which has to do context based decisions of what object type the string in “string”.dosomething() is, before it can choose the correct function “dosomething()” to execute for that object.
In that case the cmdline would look like this:
user@localhost ~ > OO-mimic.sh .mozilla.copy(~/backups)
However, this leeds to several string parsing problems, which are not very comfortable to solve in bash/shell.
Even if you “cheat” and change the syntax to something less OO-look-a-like there still is one problem left.
First, here one example of how a “better to handle and parse in bash, but cheating” syntax could look like:
user@localhost ~ > OO-mimic.sh .mozilla copy ~/backups
syntax is: OO-mimic.sh []
The one problem that is left even at this very easy approach is simply how do you decide whether “.mozilla” (the STRING, because thats what it is) is a directory or a file (or maybe a totally different object)?
OO in shell is not truely “coverable/applicable”, because you basically have only one true object type in bash/shell: “strings”.
If someone has a different oppinion please let me know by posting another comment with good points.
Thank you for listening.
Simon said,
April 9, 2008 @ 10:20
BTW: The “syntax is: ” line didnt come out quite well.
I actually wanted to say:
user@localhost ~ > OO-mimic.sh .mozilla copy ~/backups
syntax is: OO-mimic.sh _object_ _procedure_or_function_ _proc_or_func_args_ …
Eil said,
April 16, 2008 @ 1:15
Um, heh. Renaming a bunch of commands with “alias” does not suddenly give you an object-oriented shell. You need classes, methods, properties, inheritance, constructors, and destructors to name just a few of the things that are absolutely required in order to be able to apply the object-oriented label to a language.
Jeff said,
April 16, 2008 @ 20:43
First, object oriented, means to tread variables as objects with attributes or fields. Earlier posts are correctly stating that using a dot does not make a system object oriented. However, if you want to script in an object oriented manner, create shell script libraries with functions that perform discreet operations. A good book to read would be portable shell scripting. Also, try to write a small test application with a Person script and another script that calls that person script and sets and gets the field values for that person script. How can that be done? The person script must create an array and you must maintain arrays of arrays in your script.
That’s a start…
white said,
September 9, 2008 @ 19:46
u misunderstood. the OO shell, powershell, is about returning objects instead of text that you have a parse with grep/sed. aliasing cmds to pseudo namespaces doesn’t give you anything but carpal tunnel.
AA said,
October 13, 2008 @ 16:00
FUCK object oriented design. When used in small specific code is good, when used all over by fucking wanker, geeks, that don’t have social lives, it sucks.
Get a life.
jon said,
March 30, 2009 @ 23:17
what an angry group of people. jeez
SneakyWho_am_i said,
April 27, 2009 @ 22:47
Well I guess it makes it look kind of object-oriented-ish, but to really make an object oriented shell you need to actually make an object oriented shell…
Mike_A said,
May 21, 2009 @ 11:06
What a genius idea!
I had never thought about using the bash script as an object oriented language. It’s perfect:
Best encapsulation ever – process isolation. starting a process (object) is as easy as typing ‘&’
Real OO with asynchronous communicating processes. We really send messages, not fake sending messages using stack based calls.
None of that idiotic inheritance rubbish => none of the maintenance problems associated with inheritance.
It can extend any other code or system as it has the ultimate universal interface – streams of bytes.
We can secure any object in the system via permissions.
You’ve opened my eyes.
Mike_A said,
May 21, 2009 @ 11:08
btw you want / instead of dot, folders representing objects, links representing object refs, files representing properties. object construction creates a folder.
Ralph said,
August 14, 2009 @ 18:44
The technique you have mentioned is more of an object oriented naming convention. I’ve been using a similar dot naming convention for bash scripts but have never used alias to rename the obscure bash commands. It is a good idea. Now if we can only get everyone to agree on the naming convention, bash would be easier for people to learn.
Christian Laws said,
December 31, 2009 @ 23:49
Object-orientation is RETARDED altogether. Fuck Microsoft and its attempts to force us into that bullshit. I DO use classes if and ONLY if, I PERSONALLY think it makes sense for a certain purpose. But I will not create a whole program made of nothing but classes just because fuckin’ Microsoft wants me to. And attempts to extend that object-oriented bullshit to traditionally non-object-oriented concepts is even twice as retarded as object-orientation itself. And whoever is part of the object_oriented_bandwagon() is a dangerous retard who should be locked up indefinitely. And C# should be outlawed.
Ken said,
February 3, 2010 @ 13:06
I agree with several of the comments. While aliases with dot.names might be convenient and perhaps useful, I don’t see anything particularly OO in their use. As Simon/apr2008 pointed out, a ‘mimic-OO.sh’ script could be used to more closely approach object orientation, with classes, polymorphism, all that stuff, including consequent confusion and complexity if let run wild. I’ve been working on such a system and think that it is useful and promising, but am loathe to describe it here and incur the wrath of the fearful. An observation is that if bash (v4) sees a command such as ob.method, which will surely fail to resolve, a hook can be used to invoke mimic-OO.sh ob.method in its place, and the results look very much like ‘native’ objects in bash. Another is to note that method can be an ordinary executable, written in any language, shell, python, C++, whatever.
Roland said,
June 11, 2010 @ 1:16
No whitespace infront of lines of code! The hottest tip for mad coding skillz.
philluder said,
September 1, 2010 @ 14:49
Try oobash. It is an oo-style string library for bash 4. It has support for german umlauts. It is written in bash. Many functions are available: -base64Decode, -base64Encode, -capitalize, -center, -charAt, -concat, -contains, -count, -endsWith, -equals, -equalsIgnoreCase, -reverse, -hashCode, -indexOf, -isAlnum, -isAlpha, -isAscii, -isDigit, -isEmpty, -isHexDigit, -isLowerCase, -isSpace, -isPrintable, -isUpperCase, -isVisible, -lastIndexOf, -length, -matches, -replaceAll, -replaceFirst, -startsWith, -substring, -swapCase, -toLowerCase, -toString, -toUpperCase, -trim, and -zfill.
Look at the contains example:
Call the constructor:
[Desktop]$ String a testXccc
Now use object.method:
[Desktop]$ a.contains tX
true
[Desktop]$ a.contains XtX
false
http://sourceforge.net/projects/oobash/