Shell Script Thread

Impress with your OC shell scripts and oneliners.

Attached: 1468421278630.png (379x289, 75K)

Other urls found in this thread:

github.com/systemd/systemd/issues/2402
ss64.com/bash/
shellcheck.net/
developer.apple.com/library/archive/documentation/OpenSource/Conceptual/ShellScripting/Introduction/Introduction.html
pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html
man.openbsd.org/sh
man.openbsd.org/ksh
freebsd.org/cgi/man.cgi?query=sh
amazon.com/New-KornShell-Command-Programming-Language/dp/0131827006/
twitter.com/SFWRedditImages

echo no

:(

systemctl reboot --firmware-setup
Get into bios easily. Use as root.

Oh shit. This is useful.

I use something for this for backups on windows.
Compress-Archive "Foldertobackup" "where I want it saved" + get date -Format "yyyyddMM"

Gives me a zip of a folder and appends the fate. Use this in scheduled tasks.

for i in $(echo Hearts Diamonds Spades Clubs); do for j in $(echo {2..10} Jack Queen King Ace); do echo $j of $i; done; done | sort -R | head -n 4

I love writing horribly piped one liners and doing things in shell that shouldn't be done in shell.

find / -name girlfriend

is this supposed to do anything? no output on my system
...
:'(

>python
get that shit out of here

great way to kill your motherboard
github.com/systemd/systemd/issues/2402

spurdo() {
sed "s/kek/geg/gI;s/epic/ebin/gI;s/america/clapistan/gI;s/right/rite/gI;s/your/ur/gI;s/\./ :DD/gI;s/'//gI;s/,/XDD/gI;s/wh/w/gI;s/th/d/gI;s/af/ab/gI;s/ap/ab/gI;s/ca/ga/gI;s/ck/gg/gI;s/co/go/gI;s/ev/eb/gI;s/ex/egz/gI;s/et/ed/gI;s/iv/ib/gI;s/it/id/gI;s/ke/ge/gI;s/nt/nd/gI;s/op/ob/gI;s/ot/od/gI;s/po/bo/gI;s/pe/be/gI;s/pi/bi/gI;s/up/ub/gI;s/va/ba/gI;s/ck/gg/gI;s/cr/gr/gI;s/kn/gn/gI;s/lt/ld/gI;s/mm/m/gI;s/nt/dn/gI;s/pr/br/gI;s/ts/dz/gI;s/tr/dr/gI;s/bs/bz/gI;s/ds/dz/gI;s/es/es/gI;s/fs/fz/gI;s/gs/gz/gI;s/ is/iz/gI;s/as/az/gI;s/ls/lz/gI;s/ms/mz/gI;s/ns/nz/gI;s/rs/rz/gI;s/ss/sz/gI;s/ts/tz/gI;s/us/uz/gI;s/ws/wz/gI;s/ys/yz/gI;s/alk/olk/gI;s/ing/ign/gI;s/ic/ig/gI;s/ng/nk/gI" \
/dev/null
}

how's that related?

if you want that functionality, you need your efivars mounted read/write.

mandatory navy seals using that function.
wat de fugg did you juzt fuggign say about megzDD you lidtle bidch? Ill have you gnow I graduated tob of my clazs in de Navy SealzXDD and ibe been involved in numerouz segred raidz on Al-QuaedaXDD and I have over 300 gonfirmed killz :DD I am drained in gorilla warfare and Im de tob sniber in de endire uz armed forces :DD You are nodign to me but juzt anoder targed :DD I will wibe you de fugg out wid brecision de liges of wigh haz neber been seen before on dis EardXDD mark my fuggign wordz :DD You dink you gan ged away wid sayign dat shid to me over de Inderned? dink againXDD fugger :DD az we sbeak I am gondactign my segred nedwork of sbies agrosz de uzA and ur IPiz beign draced ride now so you bedter brepare for de stormXDD maggod :DD de storm dat wibes out de padedig lidtle dign you gall ur life :DD Youre fuggign deadXDD kid :DD I gan be anyweregzDD anytimegzDD and I gan kill you in over seben hundred wayzXDD and dadz juzt wid my bare handz :DD Nod only am I egztenzibely drained in unarmed gombatXDD but I have accesz to de endire arzenal of de Unided States Marine gorps and I will uze id to idz full egztend to wibe ur miserable azs off de face of de gondinendXDD you lidtle shid :DD If only you gould have gnown wat unholy redribution ur lidtle cleber gomend waz about to brign down ubon youXDD maybe you would have held ur fuggign tonkue :DD But you gouldndXDD you didndXDD and now youre payign de brigegzDD you goddamn idiod :DD I will shid fury all over you and you will drown in id :DD Youre fuggign deadXDD kiddo :DD

you can use python as your shell

kek

windows iffy uh
linux got the stiffy uh

> fixed

for i in Hearts Diamonds Spades Clubs; do for j in {2..10} Jack Queen King Ace; do echo $j of $i; done; done | sort -R | head -n 4

But cool idea!

What's this shit?

Attached: 66a.jpg (733x798, 89K)

a spurdo speak converter and music generator

:--DDd

Attached: 1428657071853.gif (512x481, 646K)

Id juzt lige to inderject for a momend :DD wat youre referrign to az LinuxXDDiz in factXDD GNU/LinuxXDD or az ibe recendly tagen to gallign idXDD GNU pluz Linux :DD Linuxiz nod an oberatign syztem undo idzelfXDD but rader anoder free gombonend of a fully functionign GNU syztem made uzeful by de GNU gorelibzXDD shell utilidies and vidal syztem gombonendz gombrisign a full OS az defined by boSIX :DD

Many gomputer uzerz run a modified verzion of de GNU syztem ebery dayXDD widout realizign id :DD drough a beculiar turn of ebendzXDD de verzion of GNU wighiz widely uzed todayiz often galled "Linux"XDD and many of idz uzerz are nod aware dat idiz bazigally de GNU syztemXDD debelobed by de GNU broject :DD

dere reallyiz a LinuxXDD and dese beoble are uzign idXDD but idiz juzt a part of de syztem dey uze :DD Linuxiz de gernel: de brogram in de syztem dat allogates de machines resources to de oder brogramz dat you run :DD de gerneliz an eszendial part of an oberatign syztemXDD but uzelesz by idzelf; id gan only function in de gondegzt of a gomplede oberatign syztem :DD Linuxiz normally uzed in gombination wid de GNU oberatign syztem: de wole syztemiz bazigally GNU wid Linux addedXDD or GNU/Linux :DD All de so-galled "Linux" disdributionz are really disdributionz of GNU/Linux :DD

rm -rf /

reddit

How does one learn basic shell scripting assuming one is a complete brainlet that can barely use ls and cd on the terminal?

Learn to use UNIX as an OS, then the scripting will make sense; or at the very least, you'll be able to look at a script, and get a vague idea of what it does. I'm a miserable scripter, but I can get around the terminal, and if I need to script, I usually can bang my head against the wall until I've got something that works.

Take a look at ss64.com/bash/ and start scripting.

use shellcheck.net/ to check your scripts for errors

>unix
Are you from the 70s? Nobody uses fucking unix. Go back to the reddit.

I'm do, and I learned it with a book from the 80s. Nothing has changed.

Attached: s-l300.jpg (186x282, 12K)

xwd -id $(xprop -root | grep '_NET_ACTIVE_WINDOW(WINDOW)' | cut -d ' ' -f 5) | convert xwd:- png:- | tee ~/Desktop/$(date +%s).png | xclip -se c -i -t image/png"

takes a screenshot of current active window, writes it to a UNIX timestamped file on the desktop, then puts the screenshot into the clipboard. needs ImageMagick. i have it bound to $mod+s in i3, then a simpler fullscreen variation bound to PrintScreen

any particular reason you use xwd+grep+xprop+convert+tee instead of just scrot?

ran this and now my computer is so much faster, thanks user!

I've really gotten into Jow Forumsgonewildaudio but one person took down a favorite clip of mine so I have a script for downloading clips in every way.
I also have filters on newsboat for downloading shit I will like, and stuff I might like while leaving out things I don't.

Attached: calc.webm (1366x768, 1.18M)

I did not know that was a flag for systemd. I knew that UEFI had that capability, and my boot menu has an entry for the firmware settings, but this is helpful as well. Did you know that systemd-analyze can show you how long the firmware and boot loader took during a startup?

I think at&t still uses unix for parts of their infrastructure.

what the fuck, calculator as a browser bookmark? why? are you stoned?

Acquire enough brain damage until you are able to read one naturally

thanks user i didn't know about this, really useful

ebin :DDDDDD

Attached: spurdo-oriented sparde-approved.jpg (229x220, 8K)

I had a one-liner that would take a few bytes from urandom, convert them to either decimal or something (I forget), then repeatedly print that out and move the cursor to the beginning of the line, so you had a slot-machine-like constantly changing number until you hit Ctrl+C to stop it and get to read the last one displayed.
I don't know where it is now, I'll try to find it.

This tutorial is good, unironically so:
developer.apple.com/library/archive/documentation/OpenSource/Conceptual/ShellScripting/Introduction/Introduction.html
After you read this, any shell man page should be easy to read, and complete your learning. As other posts have said, though, learning Unix itself will vastly increase your ability to read and write shell scripts. Unix is basically made of C and shell scripts.
Additional reference material:
pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html
man.openbsd.org/sh
man.openbsd.org/ksh
freebsd.org/cgi/man.cgi?query=sh
And a decent paper book if you prefer those:
amazon.com/New-KornShell-Command-Programming-Language/dp/0131827006/
I really do recommend ksh93, but any shell will work, so you don't need to worry about that.

Back to something I said above, if you don't know C yet, you should learn C, for many Unix programs will have parts of their syntax based off of C syntax.

Learning C would be a longer-term goal, for after you know shell scripting.
As for OSes, any will work. I recommend FreeBSD if you're a total newb, since it has a great handbook. Of course, something like Fedora would work too if GNOME doesn't make you want to die.

Cringe

I like this one for POSIX compliant math
calc() { awk "BEGIN{print $*}"; }

calc '(1 + 5) / 2 * 3'
9

also works with floats btw

echo "test... test... test..." | perl -e '$??s:;s:s;;$?::s;;=]=>%-{

Nice.

Why post this?

# take screenshot, import to gimp, delete after import
scrot -bm -q100 -e 'gimp "$f" & sleep 2; rm "$f"'

# edit a file named after its own edit time
$EDITOR "$(date)"

# same but use a filename i like better because it pleases my autism
$EDITOR $(date +"%a-%b-%d-%Y-%I-%M-%P")

# get top 20 largest files and directories in the current directory
du -ah . | sort -rh | head -n20

at the time, i couldnt find a way to get both a file with the 'correct' name and have it put into the clipboard. i also wanted a screenshot tool that relied almost entirely on openbsd base system, and in my 'tistic mind it was better to have the general ImageMagick than a specific screenshot program.

obviously theres probably a way to make scrot or maim do this easily but ive grown attached to my oneliner now

Why no?

Chances are some retard runs it and then you have made someone very sad.

if they run obscufated code from Jow Forums(nel) that literally includes a warning saying "make sure you have backups" then frankly they deserve whatever happens, and it will be a valuable lesson.

I dont have xwd installed and scrot is almost the same size + can do select region screenshots.
here is your new oneliner:
scrot '%s.png' -u -e 'xclip -selection clipboard -t image/png -i $f; mv $f ~/Desktop'

replace -u with -s for region selection, or remove it for full screen.
might need to change the xclip part for bsd.

pretty sure you can teach people things without making them cry

nvm the xclip part, didnt know -se c was an abbreviation

huh, thats a hell of a lot simpler than the original. time to install scrot

The most used shell script I wrote rips a list of movies fromy kodi database, and automatically downloads trailers from YouTube to use with the CinemaExperience plugin.

Is handy, runs every night as a cron job on my OSMC install

Bumping for more interesting scripts.

curl cheat.sh

calc is used for PoC
it means he can run commands through his browser and never use terminal