Published: 29. 3. 2017   Category: GNU/Linux

Ten completely useless bash commands, scripts, and one-liners

  1. There is a inspirational book, it is called 10 PRINT CHR$(205.5+RND(1)); : GOTO 10. Its name in bash can be written like this:
     
    while :; do printf \\$(printf '%o' $[47+45*(RANDOM%2)]); done
    
    You can also play with random alternation of different characters:
    while :; do printf \\$(printf '%o' $[45+79*(RANDOM%2)]); done
    while :; do printf \\$(printf '%o' $[123+(RANDOM%4)]); done
    
  2. In modern days, some of us missing analog TV noise. Because it remains us the importance of universe and its creation by the big bang. This one-liner simulates TV noise effect in your terminal:
    P=(' ' █ ░ ▒ ▓);while :;do printf "\e[$[RANDOM%LINES+1];$[RANDOM%COLUMNS+1]f${P[$RANDOM%5]}";done
    
  3. Another super cool effect, at least for 80s kids is a Knight rider effect:
    while :;do for i in {1..20} {19..2};do printf "\e[31;1m%${i}s \r" █;sleep 0.02;done;done
    
  4. Every Installfest provided by Silicon Hill, we've put some strange code on T-shirts. In 2013, I have sent my suggestion but it was not chosen because other geeks found it too weird:
    A=(105557416050692  77176372792420  111263447882950 111089501671460 111298948435175)
    A+=(140745122766848 140746759356416 140738707374080 140739778977792 140754249564160)
    for i in ${A[@]};do echo "obase=2;ibase=10;$i"|bc;done|sed -e 's/1/ /;s/0/ /g;6i\ '
    
    My goal was to remind years when computer magazines where printing compiled programs as BASIC source code full of DATA commands and number sequences.
  5. Rot13 encoder and decoder:
    echo "Nyvpr fraqf frperg zrffntr gb Obo." | tr 'a-zA-Z' 'n-za-mN-ZA-M'
    
    This is a variant of famous Ceasar code. Every cryptography course starts with it. Now, you can easily skip the lesson one.
  6. Destroy your terminal, completely:
    printf "\e(0"
    
    It enables flag for semigraphics characters display. The day before I will quit my job I will put it into /etc/bashrc on all production servers. (To escape semigraphics mode, reset terminal settings: tput sgr0.)
  7. A cat jumped on the keyboard and the result is:
    :(){:|:&};:
    
    Yes, and it is a really valid bash code, that can send your current operating system session into the hell. It defines a function ':' that calls itself twice and puts it into the background. Because each : call will create two more processes, it will quickly eat all system resources and your OS will hang-up and you will need to perform a hard-reset. This script is called Shell-bomb.
  8. Are mathematics and bit logics functions beautiful? If your answer is yes, I have a bad news for you: you are a nerd. So welcome to the club and check this two-liner:
    for((y=0;y<$[LINES-1];y++));do for((x=0;x<=$COLUMNS;x++));do 
    printf "\e[${y};${x}f\e[38;5;$[232+(x^y)%24]m\u2588";done;done
    
    This command generates famous XOR-texture with gray scale ANSI colors.
  9. One of the most important POSIX signals is SIGINT, usually invoked by pressing combination of Ctrl-c. You can simple redefine other keys as SIGINT sender. For example Return:
    stty intr $'\r'
    
    This command is another suggestion for a prank in /etc/bashrc. Try to fix the current shell behavior without a logout :) Big help: you can use Ctrl-j as an alternative to Return.
  10. Utility called dialog is used for textual widgets, if you need get some free-time, because your computer is blocked with something very very important, use following command:
    for i in {0..100}; do echo $i | dialog --gauge "Upgrade in progress" 10	70 0; sleep 1; done
    
    Don't forget to prolong the sleep constant!
  11. Hey, index eleven in list of 10?! Yes, this is a bonus one:
    curl -L http://git.io/unix
    
    Isn't it?