[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

>year of the current >not scripting in bash excuse me?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 73
Thread images: 8

File: 1494781732870.png (234KB, 545x530px) Image search: [Google]
1494781732870.png
234KB, 545x530px
>year of the current
>not scripting in bash
excuse me?
>>
I use sh. It's nice to not need to install bash to use my scripts.
>>
>>61494623
I use actual programming languages instead. I like portability and non-cancerous/less cancerous syntax and semantics.
>>
>need some fast file manipulation
>boot up fish
>need something a little more complex
>write a python script so i can actually do it without wishing for death or having to google for every single retarded arcane weird syntax detail

when would i use bash script
>>
I use sh for scripts and zsh as an interactive shell.
>>
>>61494667
>What kind of hipster-ass distribution are you using that doesn't have bash as its default shell?
>>
>>61495431
*BSDs, debian / ubuntu etc use dash as default i believe but use bash for users
>>
>>61494724
how is bash not portable? it runs on almost every modern OS.
>>
if anyone wants to discuss this topic but with a cute liyu0109 op please visit:
>>61495063
>>
>>61495514
OpenBSD uses ksh by default, which is similar to dash.
>>
>>61495550
>linux
>bsd
>homOSeX
>modern
no

And I'm sure even that's a moot point since apart from miserable core userland from the 70s there are probably lots of tools missing in each other.
>>
>>61494623
Why are there 2 threads?
>>
>>61495595
It runs on Windows too.
>>
>>61495563
It's a ksh88 clone
>>
>>61496218
while dash is based on netbsd sh
>>
>>61496205
Not really, though.
>>
>>61496244
https://msdn.microsoft.com/en-us/commandline/wsl/about
Now go play outside, kiddo
>>
>>61496260
It's slow and doesn't support everything, faggot. And it never will. And history suggests that MS will just leave it as half-assed.
>>
>>61496260
>>61496282
More important, I don't see what it offers over a real programming language. And you wish bash had as good package management. At least as long Perl isn't concerned.
>>
>>61495431
Bash is a part of the GNU project. I guess distros that don't want to depend on their software will use something else.
>>
File: IMG_0937.png (54KB, 1344x770px) Image search: [Google]
IMG_0937.png
54KB, 1344x770px
>>
R8 my script
#!/bin/bash
tmpfilename=$(mktemp)
currdir=${PWD##*/}
for name in `ls`
do
if [[ $name =~ .*\.(mkv|mp4|avi|webm) ]]
then
echo "$name" >> $tmpfilename
fi
done
mv $tmpfilename "${currdir}.m3u"
chmod 644 "${currdir}.m3u"
>>
>>61496417
Kinda expected asm to be faster.
>>
https://www.youtube.com/watch?v=olH-9b3VJfs

reminder that BASH is not a good SH scripting replacement
>>
>>61495431
OpenBSD
>>
>>61494623
>bash
absolute shit
>>
>>61494623
any kind of shell scripting is a meme for anything but incredibly basic tasks

it's not 1970 anymore bryan
>>
Why use bash over python? Can you make programs in bash????
>>
>>61494623
but i do senpai

cronjobs are better than init too
>>
>>61498897
What is a "basic task"? There are programs written in shell, e.g. Pass.
>>
>>61498942
say quickly parse some log files

programs have been written in shell, yes

that does not mean it is a good idea
>>
File: Screenshot_2017-07-08_00-10-31.png (134KB, 923x1163px) Image search: [Google]
Screenshot_2017-07-08_00-10-31.png
134KB, 923x1163px
>>61498920
Bash is fairly feature rich compared to legacy shell, so you can. And of course it being a shell, calling other programs and piping is trivial, wheres in Python you have to import multiple modules for tasks that are builtin in shell, and sanitize input more strictly.
E.g. regex in bash is simply:
[[ string =~ expression ]]

Python:
import re
blah blah
>>
>>61498981
There are many ways to "quickly" parse log files in shell, from builtin to using awk. Shell is probably as easy as any other interpreted language, if not easier.
>>
>>61499040
exactly, it's fine for that

when things get more complex you want to use a better language
>>
>>61496417
>programs are faster than scripts
wow
>>
File: _.jpg (21KB, 300x300px) Image search: [Google]
_.jpg
21KB, 300x300px
>>61496448
what in the fuck
>>
>>61496417
fucking luajit
>>
>bash

Only in a sick, degenerate, Jewified society is something this morally abhorrent is possible
>>
I personally use mksh for interactive, rc for scripting.
>>
Dude if you aint scripting all your shit in bleading edge object oriented perl you're doing it wrong.
>>
>>61495550
even as powerful as bash builtins are nowadays there are still a shitload of things you have to fork and exec external shit to actually do anything semi useful in a shell and some shit that's pretty much fucking required in shell scripting like jq or curl might not even be installed.

Granted, in terms of "core utils" you generally don't need to worry about BSD garbage most times, but sadly you have all these "cli cool kid" mac hipster fags with the most garbo ass coreutils bitching about how their grep doesn't recognize option -P. fuck BSD shit utils so much.
>>
>all these cucks using garbage ass ash, dash or """sh""" for scripting

you're all fucking plebs with slow ass shellscripts.

I bet you kids don't even know about shit like mapfile, arrays, read splitting, many of the fucking basic parameter expansions to avoid making calls to slow ass DSLs like awk, sed, etc.
>>
#!/bin/bash
while :
do
IFS=$'\n' read -d '' -ra toparray <<< "$(top -b -n2 | grep -E '(top - |Tasks: |Cpu\(s\)|KiB Mem|KiB Swap)')"
IFS=' ' read -ra topline1 <<< ${toparray[0]}
IFS=' ' read -ra topline2 <<< ${toparray[1]}
IFS=' ' read -ra topline3 <<< ${toparray[7]}
IFS=' ' read -ra topline4 <<< ${toparray[3]}
IFS=' ' read -ra topline5 <<< ${toparray[4]}
uptime=${topline1[4]}
brightness=$(awk '{print $1/$2*100}' <<< "$(cat /sys/class/backlight/*/actual_brightness) $(cat /sys/class/backlight/*/max_brightness)")
IFS=' ' read -d '' -r -a alsasound <<< $(amixer sget Master | grep 'Mono: ')
clr1="\e[37m"
clr2="\e[32m"
echo -e "
$(uname -sr)
$clr1 Up:$clr2 ${uptime:0:-1}
$clr1 Proc:$clr2 ${topline2[1]}
$clr1 Active:$clr2 ${topline2[3]}
$clr1 Cpu:$clr2 $(awk '{print 100-$1}' <<< ${topline3[7]})%
$clr1 Mem:$clr2 $((${topline4[7]} / 1024)) MiB / $((${topline4[3]} / 1024)) MiB
$clr1 Net in:$clr2 $(netstat -ei | grep 'RX packets' | awk '{sum += $5} END {print int(sum / 1048576)}') MiB
$clr1 Net out:$clr2 $(netstat -ei | grep 'TX packets' | awk '{sum += $5} END {print int(sum / 1048576)}') MiB
$clr1 Battery:$clr2 $(</sys/class/power_supply/BAT0/capacity)%
$clr1 Brightness:$clr2 ${brightness:0:5}%
$clr1 Volume:$clr2 ${alsasound[2]}
$clr1 Wifi:$clr2 $(tail -n1 /proc/net/wireless | awk '{ print int($3 * 100 / 70) }')%
$clr1 $(date '+%c')
\r" | tr -d '\n'
tput civis
done


https://github.com/chiru-no/cloveros/blob/master/home/user/stats.sh

I'm rewriting this in C because it uses way too much CPU for what it does.
>>
>>61496448
>
for name in `ls`


wtf you doing you literal nigger, use globbing here you fucking nigger.

use shellcheck as well so it will yell at you for being a tard ass.
>>
>>61496417
wow literally zero source or explanation of what's being done here.

you're like that tard ass who points to like a shell script taking 30 seconds to process ~10,000 lines of shit but you have something like sed being called for simple transformations that can be done almost instantly with something like "${yourline/somememe/repl}"
>>
>>61495554
we prefer frogs
>>
>>61501067
lad you're abusing herestrings too much

first read line would probably be faster if you used < <() which will spawn a subshell and output to the input of whatever command. herestring and that $() expansion will block.

also consider mapfile instead of a while read if your reading in a lot of lines and not really doing anything to them til later, mapfile is fuck ton faster.
>>
>>61496282
Bash works perfectly on WSL.
>>
>>>61494667
>>What kind of hipster-ass distribution are you using that doesn't have bash as its default shell?

Whats wrong with portability
As long as its posix compliant who cares?
Also that isnt how you use greentext please dont misuse this feature as it is meant for quoting
Im surprised you havent gotten a reply of "who are you quoting" anyways have a good day friendo and stop bashing other peoples shell!!
>>
>>61501051
t-teach me senpai
>>
>>61501051
>writing programs for quick/temporary fixes and simple things where speed doesn't matter
Yeah, nah. I'll stick to a script. Scripts and programs both have their places, quit acting like one is always the answer. It's like saying fuck a backhoe, use a steamroller
>>
>>61501824
modernperl.pdf. Its like super shell
>>
File: 167383475483.png (634KB, 1280x1280px) Image search: [Google]
167383475483.png
634KB, 1280x1280px
>>61494667
I also use sh for my scripting.

>>61495431
What kind of reddit-ass faggot doesn't know how to greentext on 4chan?
>>
>>61499002
Try doing this in Bash:

https://pastebin.com/1H3UzmM5
>>
File: Costanza.png (984KB, 1166x849px) Image search: [Google]
Costanza.png
984KB, 1166x849px
>>61494623
>year of 1974
>not scripting in lisp
excuse me?
>>
I agree with OP, but imagine being so retarder you literally don't know when not to use bash
>>
>>61502688
>I'll just add something to the command, that's all
>It's just a little regex
>now I just have to run a for loop
>it'll be perfect if I just...
>>
>>61501051
>mapfile
shit no one needs
>arrays
I think they do exist in sh
>read splitting
shit no one needs
>basic paremeter expansions
shit no one needs

also tf dsl stand for
>>
>>61494667
literally every *nix has bash preinstalled
>>
>>61502723
Nope, the best distro doesn't have it.

https://alpinelinux.org
>>
>>61502723
That's literally false.
>>
>>61502723
The world's most popular Linux distro doesn't even have bash
>>
File: 1391057239338s[1].jpg (5KB, 200x200px) Image search: [Google]
1391057239338s[1].jpg
5KB, 200x200px
>case
>esac
>>
How to become bash hacker?
>>
>>61495431
>>61502723
Many embedded Unix systems don't have bash, like openwrt.
>>
>>61503122 >>61503161 >>61503189 >>61503255
then you can easily install it or use real distros
>>
>>61503307
See >>61494667
>It's nice to not need to install bash
Sure I could install it, but I'm not going to when sh works. Why would I plague my system with unnecessary GNU bloatware when I don't need to?
>use real distros
That's exactly what I'm doing.
>>
>>61494623
Well I use python.

Also use it for programming.

Works pretty well. Fully cross platform etc.
>>
>>61501067
Fixed some of it, I don't have bash 4.4 though

#!/bin/bash
tput civis
while :
do
mapfile -t toparray <<< "$(top -b -n2 | grep -E '(top - |Tasks: |Cpu\(s\)|KiB Mem|KiB Swap)')"
mapfile -t volume <<< "$(amixer sget Master)"
IFS=' ' read -ra topline1 <<< ${toparray[0]}
IFS=' ' read -ra topline2 <<< ${toparray[1]}
IFS=' ' read -ra topline3 <<< ${toparray[7]}
IFS=' ' read -ra topline4 <<< ${toparray[3]}
IFS=' ' read -ra topline5 <<< ${toparray[4]}
uptime="${topline1[4]} ${topline1[5]}"
uptime=${uptime:0:-1}
uptime=${uptime%, }
cpuidle=${topline3[7]}
cpuidle=${cpuidle%.*}
mapfile -t netdev <<< "$(</proc/net/dev)"
netdev=${netdev[-1]}
IFS=' ' read -ra netdev <<< ${netdev}
volume=${volume[-1]}
IFS=' ' read -ra volume <<< ${volume}
volume=${volume[3]}
volume=${volume:1:${#volume}-2}
mapfile -t signal -ra signal <<< "$(</proc/net/wireless)"
signal=${signal[2]}
IFS=' ' read -ra signal <<< $signal
signal=${signal[2]}
signal=${signal:0:-1}
signal=$((signal*100/70))
clr1="\e[37m"
clr2="\e[32m"
echo -e "
$(uname -sr)
$clr1 Up:$clr2 $uptime
$clr1 Proc:$clr2 ${topline2[1]}
$clr1 Active:$clr2 ${topline2[3]}
$clr1 Cpu:$clr2 $((100-$cpuidle))%
$clr1 Mem:$clr2 $((${topline4[7]}/1024)) MiB / $((${topline4[3]}/1024)) MiB
$clr1 Net in:$clr2 $((${netdev[1]}/1048576)) MiB
$clr1 Net out:$clr2 $((${netdev[9]}/1048576)) MiB
$clr1 Battery:$clr2 $(</sys/class/power_supply/BAT0/capacity)%
$clr1 Brightness:$clr2 $(($(</sys/class/backlight/*/actual_brightness)*100/$(</sys/class/backlight/*/max_brightness)))%
$clr1 Volume:$clr2 $volume
$clr1 Wifi:$clr2 $signal%
$clr1 ${topline1[2]}
\r" | tr -d '\n'
done
>>
>>61503793
It's perfect https://github.com/chiru-no/cloveros/blob/master/home/user/stats.sh
>>
File: 1499452385859.jpg (22KB, 418x397px) Image search: [Google]
1499452385859.jpg
22KB, 418x397px
>>61502190
>My greentext skills are impeccable, tf you talking about?
>>
>>61500938
>Hillbilly redneck tries to talk fancy
>throws in an extra "is".
>>
$ file /bin/sh
/bin/sh is a symbolic link to dash

#!/bin/bash it is then.
Thread posts: 73
Thread images: 8


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.