I'm interested in knowing what people use bash scripts for, professional or otherwise...

I'm interested in knowing what people use bash scripts for, professional or otherwise. I am currently learning bash scripting in my spare time and loving it.

Attached: bash.png (1600x674, 93K)

Other urls found in this thread:

en.wikipedia.org/wiki/Scripting_language
blog.robertelder.org/bash-one-liner-compose-music/
en.wikipedia.org/wiki/Brian_Fox_(computer_programmer)
blahblah.blah/some
twitter.com/NSFWRedditVideo

Screenshot script, screencast script, auto update the distro, install script, qemu configuration, converting folders to cbz, configure my internet, simple stuff like that

cronjobs syncing data for businesses and personal stuff like backups, data manipulation, retrieving, extracting, searching files.

for everything that doesn't require calculations or complex logic - then I move to python.

>python
>calculations
>logic
>complex anything

This.

Attached: 1502523837660.gif (200x200, 91K)

I've two scripts in use constantly: One is a wrapper to use borgbackup with cron across multiple machines, the other one toggles various values when docking or undocking my laptop. The rest of them is mostly she'll commands that are too long to alias

Use batch everyday at work, works great but limited sometimes

>I'm interested in knowing what people use bash scripts for
nearly everything
just wrote a little script to generate video thumbnails on-demand for pcmanfm (didn't want to bump the thumbnail filesize minimum up, this thing is slow as fuck)
did a few others to call youtube-dl with certain parameters, and a few others to use netpbm tools to display images on the terminal

there's other shit, this is just what I've done in the last week

man, I've had to resist writing really complicated things in bash
the awful arithmetic support has saved me from trying most of the time

This

My rule of thumb s use bash for commands that could be run by hand but are tedious to keep running over and over. If it's not immediately obvious what it's doing use something like python.

Attached: 1520345923041.jpg (462x600, 47K)

>did a few others to call youtube-dl with certain parameters

full scripts for that?
i don't do much Bash, but last I checked couldn't you define functions in your bashrc for that sort of thing?

bash = harmful bloat
t. brainlet

ffmpeg stuff
simple automated tasks like saving filenames/foldernames in bulk
simple wget/aria2c downloaders

scripts for installing a ton of shit on a new system. You can use it as a language-agnostic build system that calls all your build tools and cleans shit up. Storing complex commands with a ton of flags. Anything more complicated and it is better to pick up Python or Perl.

Anything that feels like a chore calls for a bash scripts. Most of things I did in bash at work are build scripts and docker entrypoint stuff, but I also did an integration tests runner for inhouse python and R frameworks.

I have my ~/bin folder backed up on 2 flash drives and 3 magnetic drives in 3 locations. If I lost them (and my dot files) I would seriously consider killing myself

*Bash*, not that cancerous degenerate language

It werks fag, it just werks

This

Attached: 1523870162298.gif (315x572, 95K)

Most machine learning is done in python.

en.wikipedia.org/wiki/Scripting_language

you should not be so dependent on custom stuff, user

-cronjob starts script to collect automaticly some data from websites and sent once every day a summary by Email
-converting files
-Babyphone with Raspberry Pi & Bash: With an USB microphone a script listen into a room and every 5s is decided if a certain noise
level is exceeded, if yes > then an instant message is sent via mobile phone.
-A script copies important files to another directory and verifies if the checksums are equal after copying
-made a timelapse movie from 4days footage of houseconstructing and added some nice music
- had 7000 fotos from 4 different cameras (so the filenames started with different letters/numbers)and wanted to sort
and rename by date of creation

-very nice:
blog.robertelder.org/bash-one-liner-compose-music/

True. I had to use someones else's box and needed to use "lsmnt" which I couldn't find. (I had aliased findmnt to lsmnt to go with lsblk)
Not giving up my custom .vimrc though

Why would you use bash when objectively better options exist?
You do realize you don't have to script in the same language as your terminal prompt, right?

You clearly don't understand the elegance of shell scripting.
It's all about gluing useful utilities together to automate different task, and shell scripts are probably the most efficient way to do it.
You never actually write "real" programs with it.

I'd rather write real programs that have actual features and call them from the shell.

Have fun wasting your time.

Same to you, thanks.

The shell scripts I have written have saved me probably hundreds of hours at this point, and they didn't even take long to write.

>Why would you use bash when objectively better options exist?

If you're going to go and require you/users go and install a shell that's not there by default, you might as well write Ruby or Python.

bc works for minor maths related code.

>time to implement argument parsing and sanitization
>ends up being more code and more complex, especially if you want to support both long and shortform options and reading from both file and stdin, than the actual script
Every time.

Attached: 342342423423.png (500x500, 279K)

>bash
>en.wikipedia.org/wiki/Brian_Fox_(computer_programmer)

Write your scripts against dash. Use bash only when its absolutely necessary. Most of the time you don't actually need to use bashisms

I use it to speed up commands i frequently input. Automation automation automation.

>against dash
Dash is just an implementation of the POSIX shell, so that's what you're actually targeting.
But yes, dash is good to test against to make sure your didn't fuck it up.

I mostly use them for build scripts. Thinks like installing my package on the machine or creating a folder/zip with the application releasable binary and assets packed in.

's/dash/sh/'

See >Dash is just an implementation of the POSIX shell, so that's what you're actually targeting.

I saw it

that's what I meant, its just on certain systems sh is a symlink to bash, so that leads to some confusion

Loving bash???

fi .... fi
case ... esac
[[ ]], $(()), (), {}

Sometimes whitespace is very important many times it's irrelevant. Where documents only support hard tabs as indentation. It is impossible to love bash.

With that said, i use it for everything, windowmanagement, executing commands, filemanagement.

Bash is a shell, i often use awk when i need to work with strings longer then two words, but i use awk inside the bashscripts. Bash itself is retarded, but it is perfect to glue together all the good parts that makes a unix based system.

The worst thing about bash is that the irc channel is moderated by idiots

test vs [ ?

Obviously [ is faster to type and tries to mimic the notations of other languages, but explicitly using the test utility feels more consistent to every other utility like
if grep -q ...
then
...
fi

Both are builtins so they shouldn't affect performance.

probably
this was easier and they take other arguments
no point in cluttering up .bashrc instead of just plopping a script into ~/bin/ either

someone on Jow Forums wrote something which allows me to rename either a single file or an entire folder full with their md5/sha checksum.

Don't do this. Bash features make it easier to write safe shell scripts, especially when you learn how to use arrays instead if relying on word splitting or other stupid shit.

So I want to write a bash extension creating an operator &&& that works kinda like && except it repeats the same command each time.

So
sudo apt update && sudo apt upgrade -y
would become
sudo apt update &&& upgrade -y

Or
mix deps.get && mix phx.server
becoming
mix deps.get &&& phx.server

I haven't done any bash scripting yet, only worked with the command line. Does this feature already exist? If not, how would I go about implementing it?

>objectively better
only autisiths deal in absolutes

right tool for the job m80

look at him go haha how does he have so much energy?

Next step: have the script rename the file, but then add the original filename to the tags (e.g. tmsu) for the file.
That way you don't lose precious info such as "loli gagging on canine futa cock"

I'm happy you're happy, user.

This. Here's an example of something simple, which performed much faster written in python. I had a file full of URLs that needed to be encoded.

#!/usr/bin/python2
import urllib
import sys

#usage: ./encode.py < URLs.txt
#
# OR
#
# echo "blahblah.blah/some url, with retarded.. chars!" | ./encode.py
#
#output: http%3A//blahblah.blah/some%20url%2C%20with%20retarded..%20chars%21


try:
with sys.stdin as f:
for line in f:
print urllib.quote(line.rstrip('\r\n'));

except KeyboardInterrupt:
sys.exit(0);


Try doing that shit in bash and you'll be waiting a long fucking time for a 20MB file to complete.

dash is faster

stupid question here: why force close the sys.stdin in a with statement, if all streams are closed automatically when the program exits?

My autism stopping the output of "KeyboardInterrupt" to stderr. Just a personal preference.

My autism would add a "# don't print exception when user quits via ^C" comment under the except, so as to answer the "why"

oh thanks pretty useful. thanks!

Oh I see what you're referring to actually. You could technically drop the "with" line and refer to sys.stdin in the for loop. Good point.

Why python2 though?

Why use bash then? Just use sh(1) instead of that shit. No way I'm gonna install bash on my *bsd machines

s/functions/alsiases/

This. If sh can’t do it and you need bash, you’re not far off from just using Python, Perl or just C.

bash is a shell and dash is a command interpreter, you probably already have both installed, and /bin/sh is a symbolic link to dash.

>ffmpeg
>wget
I like your style.

Use [[

sudo $(apt update && apt upgrade)

If you RTFM then you probably can even launch apt in a better way

>-Babyphone with Raspberry Pi & Bash:
I hate /nu/-g

>he unironically uses python 3
python 2 is the only python relevant bro

Attached: 1522364155912.png (332x166, 2K)

Truly a master of his domain

Nothing desu. I script my shit in Python.

Attached: 1504540718799.png (560x530, 176K)

>not using each where appropriate

sudo apt update && !!:-1 upgrade -y
mix deps.get && !!:-1 phx.server

I would use this over [ in bash, but I think invoking test directly feels more consistent than either [ or [[, since it is the same syntax as calling any other program and testing if the exit code is zero.

I just created an alias called "update" that strings the two together with &&.

Backup routines, monitoring scripts, automate shit, etc.

Once i build a http server using only bash for my graduation. Was quite fun and i learned a lot about the protocol. A shame that everyone else just search something on git and pretend to have done the work. That moment i realize that graduation is a fucking meme.

>needs to organize folder by filetype
>cd into directory and muhorderingscript
>oh no, I'll make an application for that! With GOoeyi and add some functions!
>I should definitely add function to ping google in it!
Dumb example, but I hope you get the point.

Check out ShellCheck if you haven't

I use bash scripting to make difficult choices...
declare -i r=$RANDOM%$sample_size+1