User avatar
celeste_hearts_lesbianceleste_hearts_transceleste_hearts_demisexual flori_ava_star:~cursor_blinking @star@amazonawaws.com
2mo
man i have been using Linux for weeeell over a decade now and I only learned *today* that !! is a shell expansion for the last command you executed?? That means you can
$: some-command --which-is-very-long --and-moving-the-cursor-to-the-beginning-might-be-a-hassle
ERROR: command requires root privileges
$: sudo !!
INFO: yay success :3


that's so fucking handy
neobot_aww
:drgn_heart@not.an.evilcyberhacker.net:1:drippy_heart_purple_outline@irlqt.net:1:neobot_heart_cyan@thegayagenda.fans:1:neobot_pat@kittyy.mom:1:neocat_heart_f@transfem.social:1❤️7
21
31
57
12

User avatar
Brahvim @Brahvim@mastodon.gamedev.place
2mo
@star ...Wait, wasn't somebody discussing-

It was
@swirly! Swirly said he thought !! was one of the FIRST expansions one learned...!

Since everybody's sharing shortcuts:
-
Alt + F to move a word forward, though Alt and arrows do that too! Alt + B to move back a word.
- I hope everybody knows
Alt + Backspace does...!
- Did you know Termux turns
VolumeDown into Ctrl and the other into Alt?
- GNU
nano lets you use Esc to simulate Alt! Double-Esc is Ctrl.
0
0
0
0
User avatar
timorl @timorl@social.wuatek.is
2mo
–and-moving-the-cursor-to-the-beginning-might-be-a-hassle
Do you know about our lord and savior ^A?

I unironically love how all these problems have multiple solutions, so you never know all of them, because you might know another one.
blobfoxlaugh
1
0
2
0
User avatar
celeste_hearts_lesbianceleste_hearts_transceleste_hearts_demisexual flori_ava_star:~cursor_blinking @star@amazonawaws.com
2mo
@timorl I did not! Despite having lived on the shell for a kind of long time now, I am very scared of accidentally pushing the wrong button combination. Sometimes I press Alt+Backspace but instead of deleting the last word, it goes through my shell history in a weird way. I live in constant fear, but I am too ADHD-brained to then make a 30s detour to either research the correct combination for what I intended or to search how to change the combination in my shell or terminal emulator to what I wanted it to be neocat_dizzy neocat_solder_googly neobot_think_smart
1
0
0
0
User avatar
twi @confusomu@twoot.site
2mo
@star @timorl shells (and other terminal programs) typically use readline(3) to provide interactive text entry. i recommend reading its manual to learn all of the available and configurable commands/keyboard shortcuts: man 3 readline
0
0
0
0
User avatar
6 @6@possum.city
2mo
@star that's a bash-specific thing, and there's actually a lot more useful ones too
you can specify Nth previous command
you can specify Nth argument of previous command
or just the command without arguments

I usually just turn that off, it's more annoying than useful to me

www.gnu.org/software/bash/manual/bash.html#Event-Designators

some of them ARE pretty handy, like "Refer to the most recent command preceding the current position in the history list starting with string." and "Quick Substitution. Repeat the last command, replacing string1 with string2." and see some other stuff around there too, like the example given in next section "designates the second argument of the most recent command starting with the letters fi.", you can do faaaaaaancy stuff with this
0
0
0
0
User avatar
Alexia ΘΔ @alexia@app.wafrn.net
2mo
@star

I actually found this out somewhat early but I had to un-learn it because fish doesn't have
!! and I bet stuff like nushell might not either neocat_pensive_256
3
0
1
0
User avatar
Caesar Rylan @TheDarkBomber@mastodon.online
2mo
@alexia @star i use a fish plugin to have !! functionality in fish, it even works better because it puts the command in the terminal when you use it so you can edit it if you want

github.com/oh-my-fish/plugin-bang-bang
0
0
1
0
User avatar
Pile of Oxides spinny_neofox @PileOfOxides@critter.cafe
2mo
@alexia @star
Fish let's you press Alt+S instead!
1
0
2
0
User avatar
Alexia ΘΔ @alexia@app.wafrn.net
2mo
@PileOfOxides @star

TIL! ty :)
1
0
1
0
User avatar
luna aria ielenia kwon katze cascadia @ielenia@ck.catwithaclari.net
2mo
@alexia @PileOfOxides @star pressing that will also add sudo to whatever command you're currently typing too :3
0
0
2
0
User avatar
Piko Starsider verified_paw @starsider@valenciapa.ws
2mo
@alexia @star fish does have it, or at least it does have it now.
0
0
1
0
User avatar
Nora, of the E-gemony spinnycat_trans @pinkberet@transfem.social
2mo
@star That is absolutely correct!!
0
0
1
0
User avatar
Freeeeeeeeeeeeee ablobfoxbongohyper fluffytail @freeplay@wetdry.world
2mo
@star yeahg i accidentally found that out writing commit messages with foxi sounds neofox_floof
0
0
1
0
User avatar
Caesar Rylan @TheDarkBomber@mastodon.online
2mo
@star yeah it's cool, another feature i like is !$, which repeats the last argument, so if you want to move and then edit a file:

mv -v a.txt b.txt
text-edit-command !$
0
0
1
0
User avatar
Kooda @Kooda@loutre.info
2mo
@star ctrl-a and ctrl-e to go to the start and end of the line is also useful :)
0
0
0
0
User avatar
Shani ✨ @shani@cuties.social
2mo
@star i know that for years now, and i always forgot, that it exists, when it could be handy at the moment ^^'
1
0
1
0
User avatar
6 @6@possum.city
2mo
@shani @star but did you know about ctrl-x + ctrl-e
0
0
0
0
User avatar
Sammy Arson Fox ( ?markov ) @theresnotime@fox.nexus
2mo
@star WHAT
0
0
1
0
User avatar
Lyn coweat verifiedlesbian @fugi@amazonawaws.com
2mo
@star there's always another obscure cool thing one can find out about :D
0
0
2
0
User avatar
MagicLike verifiedbi neodog_flag_nb neocat_floof_fcknzs @MagicLike@soc.sekundenklebertransportverbot.de
2mo
@star whoagg neodog_surprised
0
0
1
0
User avatar
immibis @immibis@social.immibis.com
2mo
@star I think most people just press up to recall the last command, then home to go to the start. !! made more sense when people were using teleprinters.
0
0
0
0
User avatar
jade arson. captcha_silly_wolf @awoo@gts.apicrim.es
2mo
@star here's the thing, I've known about it for ages and had to unlearn it after switching shell as apparently only some of them (like bash) support !!
1
0
0
0
User avatar
6 @6@possum.city
2mo
@awoo @star yep, it's a nonstandard bash extension, along w a lot of other stuff

it's not an issue
IF you know that
problem is when people forget that other shells exist, and bash is an outlier, it's not other shells' fault they don't want to implement the 90000 extensions bash has (like being able to open network sockets via a virtual /dev/tcp/example.com/80 node and such, which doesn't exist if you try to look at it)
0
0
0
0
User avatar
cozmo @cat5e@critters.gay
2mo
@star it's pronounced "sudo bang bang" too, which makes it even better
0
0
2
0
User avatar
Anthropy @anthropy@mastodon.derg.nz
2mo
@star I also really like $_ which reuses the last argument from the previous command

e.g
$ somecommand some-really-long-argument-that-is-painful-to-type-like-a-randomly-generated-hostname

$ someothercommand $_
2
0
0
0
User avatar
6 @6@possum.city
2mo
@anthropy @star I hate it because I want to use $_ as a "dummy" argument, to indicate "we don't care about this", and that it can get overwritten at any point (a lot like social convention is in other languages)
but sometimes I want to check if the variable is filled, even if it's the only time I use it
annoying to need to use other names specifically in bash (other shells work fine ofc)
1
0
0
0
User avatar
Anthropy @anthropy@mastodon.derg.nz
2mo
@6 @star add a backslash (\) before the variable, that way it won't get interpreted c:

I primarily use it interactively though. for scripts I actually prefer not to use bash/shell, because shell substitution is extremely vulnerable to issues, exploits, etc. I only really use it if it makes much more sense than something like python, e.g if there's a bunch of shell commands I just need to chain, but if it's more than a few lines and needs string operations I often just move over to python
1
0
0
0
User avatar
6 @6@possum.city
2mo
@anthropy @star I'm not aware of any problems w shell substitution lol
the rule of thumb is Quote Absolutely Everything, tho, bc of that
special characters are only special if you forget to do that
1
0
0
0
User avatar
Anthropy @anthropy@mastodon.derg.nz
2mo
@6 @star quoting definitely helps, but there are a lot of weird ways it can interact (some of which have now been fixed): en.wikipedia.org/wiki/Shellshock_(software_bug)

I'm not going to tell anyone what to write their scripts in, I also have quite a few bash scripts myself, but it's quite a bit more finnicky and vulnerable to accidents than something like python due to the nature of its execution and substitution-based variable usage (like SQL w/o parameters), and python is there usually wherever bash is available.
1
0
0
0
User avatar
6 @6@possum.city
2mo
@anthropy @star
I may just be a masochist, idk why I like shell scripts, like really, idk why, they're objectively bad for most things lol
trying to do things in posix (not bash) shell scripts that have no business being in shell scripts
like a scrolling menu list widget (bc not bash, it has to use
dd to read input one byte at a time amiya_sob)
or ~30% of a crude dns client (it has to do decimal for math, octal for output, and handle binary for input
woozy_baa it can only send a request and parse the header structure... shell scripts are the WORST language for it, I haven't touched t in a while lmao)

I should probably migrate to doing my cursed lua + shell script hybrid thing actually
which is surprisingly less cursed than I thought it'd be, either side can call functions from the other side, it's neat!
this would let lua (an actual scripting language) do logic, and the shell be the glue to the outside world
(it basically re-executes itself for every intra-script function call, lol, not actually efficient at all)
0
0
0
0
User avatar
Spirhalite Mica celeste_hearts_non_binary @mica@mk.absturztau.be
2mo
@anthropy @star in bash you can usually also press escape followed by dot to insert the last argument from the previous command
0
0
1
0
User avatar
amy neobot_flag_finsexualneobot_flag_trans @thing@thegayagenda.fans
2mo
@star you can also just..press [UP] neobot_woozy
also, another neat (bash) trick is that you can use [CTRL]+[R] to search in your history for a command
2
0
1
0
User avatar
celeste_hearts_lesbianceleste_hearts_transceleste_hearts_demisexual flori_ava_star:~cursor_blinking @star@amazonawaws.com
2mo
@thing What I described in the post is not possible by just pressing "up"
:neobot_woozy@thegayagenda.fans:1
1
0
0
1
User avatar
amy neobot_flag_finsexualneobot_flag_trans @thing@thegayagenda.fans
2mo
@star no i meant
[UP]
[CTRL]+[A]
(type the cmd prefix)
0
0
0
0
User avatar
6 @6@possum.city
2mo
@thing @star there's also
!string

Refer to the most recent command preceding the current position in the history list starting with string.

www.gnu.org/software/bash/manual/bash.html#Event-Designators

oh and ctrl-x + ctrl-e is very useful
0
0
0
0
User avatar
💙🩷💜 Brett [he/him/any] @brettm@swarm.coiloptic.org
2mo
@star i never knew that one but also ctrl+a jumps to start of line!
1
0
0
0
User avatar
6 @6@possum.city
2mo
@brettm @star and ctrl-e to the end
and ctrl-w deletes previous word

they're readline keybinds, pretty sure

also fun fact: bash has a vi mode
by default it's in emacs mode (very silly)

also also, ctrl-x + ctrl-e is a lifesaver
it opens currently edited command in your $EDITOR
it's incredibly useful for any long-ish commands, and you can do that w an empty prompt too
0
0
0
0
User avatar
Kurt @Kurt@icy.uwu.bar
2mo
@star yea, it's neat. More people should know about that. blobCat_bongo
0
0
1
0
User avatar
229 @Nero@chaos.social
2mo
@star more generic, "history" to show the history with line numbers, and !<number> to recall any command from the history
0
0
0
0
User avatar
wfk @wfk@v.st
2mo
@star I always set the line editing of bash to vi mode, which, if you know vi, makes this kind of actions trivial, making the various other historical shell history commands and short cuts mostly superfluous.
Just one interface for file editing, line editing, shell history traversal/searching.
0
0
1
0