Thursday, September 6, 2012

Non Alpha Numeric Shellscript

Shellscript


After finishing the non alphanum php code I thought of doing the same with shellscripts. In the beginning I wasn't sure if it's possible but know I am able to say: It is :)

So lets jump into it. To begin with I built a ls command: 

/????\+?????
__=$_;
. .;
___=$?;
____=___;
____=$[++____];
____=$[++____];
${__:___:___}${__:____:___}



1. /????\+?????

This is a regular expression, which I use to search in the / for the lost+found directory. This command will print all directories, which matches the regular expression, to the standard output. 

2.  __=$_


 This will assign to the variable __ the output of the last command . The full definition can be found here


3. . .;

Actually this command throws an error, I just used it to have a return value

4.  ___=$?;

This command saves the return value of . . in ___, which is 1. This will be used as the amount of chars we want to use.


5 ____=___; 


Maybe you think this is wrong, because actually it should be  ____=$___; But that would be boring. So we just save the string ___

6.  ____=$[++____];


This command stores 2 in ____. But wait, ____ just contains a string. This is true, but this command does a double variable expansion: ____ gets to ___ which expands to 1. (I didn't look it up why it does that).


7.  ____=$[++____]


Stores 3 in ____


8.  ${__:___:___}${__:____:___} 


I think its easier with the values:

${/lost+found:1:1}${/lost+found:3:1} 

The first block takes from postion 1 just 1 character which is a l.
The second block takes from position 3 just 1 character, which is s.

And thats how it works.

No comments:

Post a Comment