370 reputation
113
bio website
location Hungary
age 15
visits member for 3 years, 11 months
seen 14 hours ago

StackFlair


Dec
22
comment How do I run a command and get its exit code in fewer characters?
The second example shouldn't include [ and ] around the commands.
Dec
20
comment Switch to parent shell without logging out
@StéphaneChazelas I didn't think of that. That's a good point.
Dec
20
comment Switch to parent shell without logging out
@StéphaneChazelas $$ is a read-only variable, though, and you can make assumptions about its value. That said, I do quote those variables when using them.
Dec
20
comment Switch to parent shell without logging out
@StéphaneChazelas Does that really make a difference with a variable that's almost certainly guaranteed to contain a numeric value?
Dec
13
comment Extracting the second word from a string variable
echo is not portable for anything other than a literal string that doesn't start with - and doesn't contain any escape sequences. Its behavior varies even for the bash builtin, depending on how it was compiled, and whether XPG_ECHO is set. Also, you should always double quote variable expansions and command substitution (with certain exceptions, where it's not necessary but it doesn't do any harm either). With a string like the OP's, this should be fine, but if you want to make sure printf '%s\n' "${a##* }" would be better.
Dec
13
comment Extracting the second word from a string variable
echo is not portable for anything other than a literal string that doesn't start with - and doesn't contain any escape sequences. Its behavior varies even for the bash builtin, depending on how it was compiled, and whether XPG_ECHO is set. Assuming the string contains no escape sequences, this should be fine, but printf '[%s]\n' "$y" is still better.
Dec
1
comment Automatic login via ssh (no GUI environment installed / no ssh-agent available)?
Then why are you talking about entering the nonexistent passphrase later on? [...] prepare the system for batch SSH usage by entering the passphrase [...]
Dec
1
comment Automatic login via ssh (no GUI environment installed / no ssh-agent available)?
You can use SSH keys which have no passphrase. If you don't like that idea then you can create a key file without passphrase [...] This doesn't make sense.
Nov
6
comment How do I set a user environment variable? (permanently, not session)
This is not a full answer, but if it's shell-specific, I recommend putting it in .bashrc; if it's not, put it in .profile. I source .profile and .bashrc (in that order) from .bash_profile, and make sure to put [[ $- != *i* ]] && return on the top of .bashrc.
Nov
5
comment Modify a file without creating another file
I can't see any globs there.
Nov
5
comment Modify a file without creating another file
I submitted an edit with some improvements. While it may not exactly be suitable for an edit, I'm hoping to save you some work.
Nov
5
suggested rejected edit on Modify a file without creating another file
Nov
5
comment Modify a file without creating another file
I think you forgot to define pattern and replacement, too.
Nov
5
comment Modify a file without creating another file
Also, if it's a bash script, you can just do grep -q "$pattern" <<< "$line".
Nov
5
comment Modify a file without creating another file
That script suffers from multiple issues. (1) read line should be read -r line. (2) The $() in the if is redundant. I'm surprised if that even works. (3) echo suffers from a lot of portability issues even within bash. Use printf '%s\n' "${var}" instead. (4) $1 should be wrapped in double quotes: "$1".
Nov
5
comment Getting 256 colors to work in tmux
-1, you shouldn't set either unconditionally in your shell initialization file. Setting it to xterm-256color will override it inside tmux as well, and setting it to screen-256color outside of tmux could lead to display bugs.
Nov
4
revised Adding to path vs. linking from /bin
edited body
Nov
4
revised How to get the name of the user who executed a bash script as sudo?
fix script as OP's intent is clear per comments; improve spelling/grammar; update tags
Nov
4
suggested approved edit on How to get the name of the user who executed a bash script as sudo?
Nov
4
awarded  Organizer