Hot answers tagged

26 votes

Run two scripts after each other in the background? && and & don't work?

That's one of the known deviations¹ of zsh compared to sh (or csh for that matters). In sh: A && B & is short for: (A && B) & That is, it runs a subshell that runs that and-...
Stéphane Chazelas's user avatar
8 votes

Run two scripts after each other in the background? && and & don't work?

You have to group the two commands together: nohup sh -c 'a.sh; b.sh' & Replace ; with && if you want b.sh to run only if a.sh exits with success
Chris Davies's user avatar
7 votes
Accepted

How to get both the number of bytes and the sha1sum with single pass?

Would be easier to use temp files. In zsh: (){set -o localoptions -o pipefail; local IFS {cmd} > >(sha1sum > $1) | wc -c | read bytes || return read checksum rest_ignored < $1 || ...
Stéphane Chazelas's user avatar
3 votes

In terminal, how to delete a word when cursor is within the word?

If you are using a shell which uses readline(3) as bash, you have either to combine two shortcuts:Alt-dAlt-Backspace Or you define a key which is not already in use, see the output of the command ...
Erich's user avatar
  • 385
3 votes

Equivalent of PSReadLine for bash

Bash, which is the default shell in Ubuntu and most GNU/Linux distribution, does not come with support for most of these fancy features. Though you can get closer with a couple tweaks to the ...
mutageneral's user avatar
3 votes

Add a process to an already executing process? Like && or so

Only the parent process (or the child subreaper if any or init if the parent died), can retrieve the exit status of a process. From the shell where you started the command, you can wait for it, and ...
Stéphane Chazelas's user avatar
3 votes

Add a process to an already executing process? Like && or so

If the shell that started the process still knows about it (try jobs), then the shell built in wait can wait for it to finish. Something like this might work: $ jobs [1] nohup a.sh $ wait -f %1 &&...
user10489's user avatar
  • 6,194
2 votes

How to get both the number of bytes and the sha1sum with single pass?

I am using a backup bash script which has the following helper "in-between" functions which take a "supposed filename" as an argument (see tar.gz example below): function pipesum { ...
legolegs's user avatar
  • 321
2 votes

Disabling the secondary prompt in zsh

There is a zsh plugin that disables secondary prompt: https://github.com/romkatv/zsh-no-ps2. If the currently typed command is well-formed, pressing Enter executes it as usual. Otherwise it inserts a ...
Roman Perepelitsa's user avatar
2 votes
Accepted

OSX13; how to mv series of x numbers of file chunks simultaneously to the series of directories

Sounds like just a matter of autoload -Uz zmv zmv '(GSM<->_<->)_*' '$1/$f'
Stéphane Chazelas's user avatar
1 vote

Function with aliased command works with eval but not shell expansion

Aliases are special. They're handled early in the command line processing, before parsing is fully done, and they work more like straight-up text replacement than calling a separate function. With ...
ilkkachu's user avatar
  • 135k
1 vote

Function with aliased command works with eval but not shell expansion

You want either: cmd=( main_cmd hard_coded_arg_1 hard_coded_arg_2 -a "$opt1" -b hard_coded_opt "$2" ) "${cmd[@]}" Where we define an array that has these ...
Stéphane Chazelas's user avatar
1 vote

identify content inside base64 encoded content and replace the whole line

Assuming you want to: find base64 encoded data after any occurrence of -encodedcommand (case insensitive) followed by whitespace decode it into something assumed to be a multiline UTF16-LE encoded ...
Stéphane Chazelas's user avatar
1 vote
Accepted

Pass ssh remote command from bash to zsh

On some (most these days) systems, bash is configured at build time so that when run over ssh, bash reads ~/.bashrc (and corresponding system-wide file in /etc) even when run non-interactively like ...
Stéphane Chazelas's user avatar
1 vote

In terminal, how to delete a word when cursor is within the word?

zsh's line editor supports all of vim's [cd][ai][wW] (even an extra [cd][ia]a as a bonus) out of the box when in vi mode (entered with bindkey -v like in tcsh or set -o vi like in ksh). See info zsh '...
Stéphane Chazelas's user avatar
1 vote

How can I automatically wrap every command in Zsh/Bash with a custom command before execution?

I will assume you will want to enter and exit out of this arrangement so I made the following. For zsh, the DEBUG trap handler can skip the execution of a submitted command by setting the ERR_EXIT ...
Joakim Hagen's user avatar
1 vote

Modify tmux run-shell PATH

The shell tmux uses inside run-shell gets environment variables from the tmux server. Depending on how you started the tmux server and what happened later, the resulting environment may or may not ...
Kamil Maciorowski's user avatar
1 vote

Key binding to swap shell foreground/background jobs

This makes issuing CTRL+Z immediately resume the previous job, as long as you have more than 1 job suspended. The only way to exit the while loop is to close programs until at most 1 backgrounded ...
Sakari Cajanus's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible