#!/usr/bin/perl #bashflash #tests your memory of bash/gnu-linux commands and cli programs #USAGE: #cd to the directory containing the binarys of the programs #you want to test your knowledge of (DO NOT NEED TO BE ROOT) #pass perl bashflash -`whatis --wildcard *` # use strict; use warnings; #The following loop utilizes a shift-and-push loop #to shift the zeroth element of @ARGV out of the array, into a scalar, #then push the scalar back into the array as the final element. #effectively, this process lets one cycle through the output of #`whatis --wildcard *` indefinitely, *while separating the #command names from their descriptions, like flashcards.* #*In it's current implementation, @ARGV stores the output of `whatis` #word by word: such that elements are delineated by spaces. my $currentcard; #this variable holds onto strings shifted off of @ARGV #, prints them, then pushes it's contents #back onto the end of ARGV while (1) { #infinite loop START $currentcard = shift; #shift first element #of @ARGV into $currentcard print $currentcard; push (@ARGV, $currentcard); #push $currentcard #(previously element 0) back onto #@ARGV as the last element ; #Wait for user } #infinite loop END exit; #the script never gets here, #but I always explicitly exit on the end of my Perl. #and then an empty comment line # #### sage@bash:/bin$ perl bashflash -`whatis --wildcard *` bashflash: nothing appropriate. kmod: nothing appropriate. ntfsck: nothing appropriate. ntfsdump_logfile: nothing appropriate. ntfsmftalloc: nothing appropriate. ntfsmove: nothing appropriate. ntfstruncate: nothing appropriate. ntfswipe: nothing appropriate. plymouth: nothing appropriate. plymouth-upstart-bridge: nothing appropriate. running-in-container: nothing appropriate. static-sh: nothing appropriate. -bash (1) - GNU Bourne-Again SHell bunzip2 (1) - a block-sorting file compressor, v1.0.6 busybox (1) - The Swiss Army Knife #### my @currentcard; #this variable holds onto strings shifted off of @ARGV #, prints them, then pushes it's contents #back onto the end of ARGV while (1) { #infinite loop START $_ = shift; while (m#^(?!-\s)$#) { push (@currentcard, $_); $_ = shift; } print @currentcard; push (@ARGV, @currentcard); #push $currentcard #(previously element 0) back onto #@ARGV as the last element ; #Wait for user } #infinite loop END #### my @currentcard; #this variable holds onto strings shifted off of @ARGV #, prints them, then pushes it's contents #back onto the end of ARGV while (1) { #infinite loop START $_ = shift; my $witch = 1; while ($witch) { push (@currentcard, $_); $_ = shift; if ($_ =~ m#^(-\s)$#) { --$witch; } } print @currentcard; push (@ARGV, @currentcard); #push $currentcard #(previously element 0) back onto #@ARGV as the last element ; #Wait for user } #infinite loop END