Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »

Activity for r~~‭

Type On... Excerpt Status Date
Edit Post #295535 Initial revision 7 months ago
Answer A: As root, how do I read another user's environment variables?
Nobody likes it when their ‘how can I do this?’ questions are answered with ‘don’t do this’, but while an answer could be given that would probably work well enough most of the time for many use cases, the question itself is contradicted by how environment variables and `PATH` in particular are e...
(more)
7 months ago
Comment Post #295505 If your script won't function unless it is run with sudo, perhaps it should run sudo itself? ``` #!/usr/bin/env bash echo "Current user: $EUID" echo "Do things not requiring root now, like searching \$PATH" sudo env what_we_found="42" "$BASH" <<'EXIT_SUDO' echo "In sudo" echo "Curren...
(more)
7 months ago
Edit Post #295454 Initial revision 7 months ago
Answer A: Replacing the shebang in a script
Sed has more commands than just `s`! You can replace the first line of the input with a new value using the `c` command, without having to write any regular expressions. ``` sed "1c\\$env" "$file" ```
(more)
7 months ago
Edit Post #295240 Post edited:
9 months ago
Edit Post #295240 Initial revision 9 months ago
Answer A: How to enter a blank line in a terminal without executing the command
> I've also tried using \ to escape the newline, but that also immediately executes, e.g. echo 'cat' \ just immediately prints > > cat > \ This shouldn't be happening. Ending a line with `\` in any sh-compatible shell is the standard way to represent a line continuation, per the ...
(more)
9 months ago
Comment Post #294901 This is a whole separate question about when parameter substitution happens, but you'll notice that the behavior changes when you replace your double quotes with singles.
(more)
11 months ago
Comment Post #294901 You can always get the exit status of the last command with `$?`.
(more)
11 months ago
Edit Post #294901 Initial revision 11 months ago
Answer A: trap ... ERR, how to get the signal code?
`ERR` is not a signal, so there is no signal code to get. From `man bash`: > If a sigspec is ERR, the command arg is executed whenever a pipeline (which may consist of a single simple command), a list, or a compound command returns a non-zero exit status, subject to the following condition...
(more)
11 months ago
Edit Post #294547 Initial revision about 1 year ago
Answer A: Can I interrupt a crashing/frozen Ubuntu desktop?
You might be looking for the Magic SysRq feature, which has many functions. One of the most useful is Alt+SysRq+f, which triggers the kernel's out-of-memory process killer. On Ubuntu, you may need to enable this feature using a sysctl configuration file. Either enable all Magic SysRq functions...
(more)
about 1 year ago
Edit Post #294057 Post edited:
over 1 year ago
Edit Post #294057 Initial revision over 1 year ago
Answer A: Temporarily making \u escapes use a different encoding on the command line
I don't think you can persuade Bash to use non-UTF-8 characters internally—I expect much of its code assumes that strings are ASCII-compatible. So `$'\u00FF'` will always translate, inside Bash, to the UTF-8 byte sequence `c3 bf`. If you want to take a UTF-8 byte sequence that Bash (or another...
(more)
over 1 year ago
Edit Post #294056 Initial revision over 1 year ago
Answer A: greedy capture with sed
The `b\+` part of the regex is already greedy. In sed, all repetitions are greedy. Your problem is that the initial `.` is also greedy, and so that's gobbling up both the `a` and as many `b`s as it can. For this example, you can change that part to `[^b]`: ``` $ sed -n 's/[^b]\(b\+\)./\1/p' <...
(more)
over 1 year ago
Edit Post #293003 Initial revision almost 2 years ago
Answer A: how to use %F in a file URI in a .desktop file
From the Desktop Entry Specification: > A command line may contain at most one %f, %u, %F or %U field code. Try storing %F in a local variable and reusing the variable. Also, take care: %F will in general expand to a list of files, which your current script will not adequately handle. U...
(more)
almost 2 years ago
Comment Post #292980 Just to make sure, you do know that the output of the `h` command (and other commands with outputs) goes to the kernel log and not your current terminal, right? You need to run `dmesg` to see it.
(more)
almost 2 years ago
Edit Post #291650 Initial revision over 2 years ago
Answer A: How do I send console output to the clipboard?
On Wayland, the `wl-clipboard` utility `wl-copy` is the program you want: ``` echo hi | wl-copy ```
(more)
over 2 years ago
Comment Post #285187 Pick one, get corrected if necessary.
(more)
over 2 years ago
Edit Post #291146 Initial revision over 2 years ago
Answer A: How do you generate arbitrary random numbers from /dev/random?
You want `shuf`. ```sh shuf -n1 -i 534-876874 ```
(more)
over 2 years ago
Edit Post #291145 Initial revision over 2 years ago
Answer A: What is cat abuse/useless use of cat?
Especially in a pedagogical context, the issue with something like `cat /dev/random | head -c 20` versus the more straightforward `head -c 20 /dev/random` is that it communicates that extra ceremony is necessary. It isn't. Using one program instead of two isn't about saving kilobytes of computer ...
(more)
over 2 years ago
Comment Post #291137 `<file1 | grep cookies | wc` might work in your shell of choice but it doesn't work in Bash. I look forward to your mocking rant about people who point out that other shells exist.
(more)
over 2 years ago
Comment Post #290827 The answer says, ‘`sudo ls ~` [prints] the contents of your actual home directory [...] This is because [...] `sudo` [...] does not change your `$HOME`’. This is doubly false, as I explained—`sudo` can change `$HOME`, and the behavior of `sudo ls ~` doesn't depend on whether or not it does.
(more)
over 2 years ago
Edit Post #290837 Post edited:
over 2 years ago
Edit Post #290837 Initial revision over 2 years ago
Answer A: How to use the gitignore file without git(1).
You can fake out `git` as long as you have some empty Git repository available somewhere. ``` git --git-dir=path-to-empty-repo/.git \ ls-files --others --exclude-standard ```
(more)
over 2 years ago
Comment Post #290827 `sudo ls ~` will not tell you whether `sudo` sets `HOME`, because the `~` is expanded by the non-root user's shell. In many distributions, `sudo` *is* configured to set `HOME` by default. There are several configuration options that determine whether `sudo` modifies `HOME` or other environment va...
(more)
over 2 years ago
Edit Post #290797 Post edited:
cat isn't needed
over 2 years ago
Suggested Edit Post #290797 Suggested edit:
cat isn't needed
(more)
helpful over 2 years ago
Comment Post #290716 Have you read what sudo does? If so, it's not clear what you want to know. If not, this is insufficient research for a question here.
(more)
over 2 years ago
Comment Post #290201 On Debian Trixie, if you have the `console-setup-linux` package installed, [the files in that package](https://packages.debian.org/trixie/all/console-setup-linux/filelist) include terminal fonts of sizes up to 16x32. And yes, the character grid is changed, not just the glyph sizes. A 16x32 fon...
(more)
almost 3 years ago
Edit Post #290201 Initial revision almost 3 years ago
Answer A: How to change resolution of virtual terminal?
This isn't exactly what you asked, but the letters-too-small problem could also be solved by using a larger console font. Here is a decent overview of how to change console fonts, though I don't know which of the `console-setup` and the `vconsole.conf` approaches is correct for your distribution.
(more)
almost 3 years ago
Edit Post #290012 Post edited:
almost 3 years ago
Edit Post #290012 Post edited:
almost 3 years ago
Edit Post #290012 Initial revision almost 3 years ago
Answer A: Rename multiple files which have a variable suffix
An easy one-liner in POSIX-compatible shells: ``` for f in -min.jpg-; do mv -- "$f" "${f%-}"; done ``` The only (mildly) tricky concept here is `${f%-}`, which expands to `$f` minus the shortest suffix matching the glob pattern `-`.
(more)
almost 3 years ago
Edit Post #289874 Post edited:
almost 3 years ago
Comment Post #289874 That is a really good catch, thanks.
(more)
almost 3 years ago
Comment Post #289874 Piping is a shell feature. If you want to use shell features, you have to be running in a shell. The `find` manual isn't responsible for pointing that out. [It is specified](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_13_03) that wildcards in shell scripts ...
(more)
almost 3 years ago
Comment Post #289874 The `\! -empty` is there because if the shell expands a wildcard that doesn't match anything, the wildcard remains, and you don't want `.../empty_dir/*` in your output. The `ls` is an unnecessary subprocess invocation. `sh` is already expanding the `*` before `ls` is invoked.
(more)
almost 3 years ago
Comment Post #289875 Fair, post edited.
(more)
almost 3 years ago