Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API

From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
netikras34554173dCool! But it's quite straightforward..
- ´ -- legacy af, never use them
- ' -- shell won't touch anything inside, ie you will have what you have. No interpolation, no nothing
- " -- shell will interpolate whatever shell expressions it finds inside
there's not much more to it than that... -
netikras34554172d@kiki not quotes. Angle brackets. They are stream redirection operators, much like in c++.
-
kiki37171172d@netikras those are Cyrillic кавычки-ёлочки, and I doubt they are part of any C++ spec. Did you mean >>?
-
netikras34554172d@kiki there's a variety of its uses. Single > ensures an empty file and streams stdout into it. Double >> -- ensures a file and does thd same [not necessarily empty, ie O_APPEND -- appends to a gile if it already exists].
< -- streams file contents into stdin [for some command].
<<< -- streams following string contents into stdin. So you can compile some input in your script into a ctring and feed itninto some command's stdin.
<< -- allows you to compose a literal multiline string and feed it into stdin; terminated by a customizable terminator [immediately following the << notation]. Also called Heredocs
<(command) -- translates into a command's stdout file [in the /proc filesystem]. I often use it for ´diff´, as it only accepts files and I sometimes need to diff command outputs -
netikras34554172d@kiki yes, that's what I meant. I assumed a genuine qn with a typo, not a troll question
-
Aldar1186172dYou know how ' are used to keep shell from touching the containing string in any way, right?
What effed me up is that in bash, if you prepend the first apostrophe with a dollar sign, it overrides that and turns on escape sequence translation within the string
$ echo 'foo\nbar'
foo\nbar
$ echo $'foo\nbar'
foo
bar -
kobenz867167d@netikras (stuff...) literally means "run wtv the fucks in there" , { stuff... } does the same with the added "don't you touch my shit"
-
netikras34554167d@kobenz not just that. () runs in a subshell, meaning once you leave (), any variables or whatever you set/export inside parentheses will no longer be available outside them.
{} is a simple code block with full access to 'parent' scope/vars/envs. {} is just a convenience allowing you to run multiple commands/subscript as one unit and treat it as such [pipe stdout/err/in, handle exit code] -
netikras34554167d@kobenz why do you say {} is 'dont touch my shit'? I'd say it's the other way around, unless we mean different things
-
netikras34554167d@retoor I guess... :)
using subshells I have implemented multithreading in bash. It's a powerful tool. So why not... -
netikras34554167d@retoor I have a webserver built in bash. Though it's single-threaded, didn't invest more time in it :)
-
netikras34554167d@retoor
bthread: https://github.com/netikras/bthread
log4b: https://github.com/netikras/log4b
bthrow: https://gitlab.com/netikras/bthrow
bhttp: https://gitlab.com/netikras/bhttp
/dev/rant: https://gitlab.com/netikras/...
you might find some of those worth looking into -
netikras34554167d@retoor shellcheck?
Though I don't use it.
And I've developed my own scripting style over time that works very well for my needs -
netikras34554167d@retoor yupp. Useful for libs. Function names can contain :, it makes scripts much more maintainable as you know which lib owns that fn
Today I've had the pleasure of wrapping my brain around shell-quoting in all its insane glory
rant